From 6220c78f744c4c505ad27f0fc3e1aff3de7b7806 Mon Sep 17 00:00:00 2001 From: fr33domlover Date: Wed, 3 Aug 2016 19:32:33 +0000 Subject: [PATCH] Extra persistent graph classes & instances for ticket graph --- .../Persist/Local/Class/PersistEntityGraph.hs | 19 +++++++++++++++---- src/Vervis/Model.hs | 11 ++++++++++- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/Database/Persist/Local/Class/PersistEntityGraph.hs b/src/Database/Persist/Local/Class/PersistEntityGraph.hs index 6f4bd81..cf4e6dd 100644 --- a/src/Database/Persist/Local/Class/PersistEntityGraph.hs +++ b/src/Database/Persist/Local/Class/PersistEntityGraph.hs @@ -15,6 +15,8 @@ module Database.Persist.Local.Class.PersistEntityGraph ( PersistEntityGraph (..) + , PersistEntityGraphSelect (..) + , PersistEntityGraphNumbered (..) ) where @@ -23,8 +25,17 @@ import Prelude import Database.Persist class (PersistEntity n, PersistEntity e) => PersistEntityGraph n e where + sourceParam :: e -> Key n + sourceField :: EntityField e (Key n) + destParam :: e -> Key n + destField :: EntityField e (Key n) + +class PersistEntityGraph n e => PersistEntityGraphSelect n e where type PersistEntityGraphSelector n e - sourceParam :: e -> Key n - sourceField :: EntityField e (Key n) - destParam :: e -> Key n - destField :: EntityField e (Key n) + selectorParam :: n -> PersistEntityGraphSelector n e + selectorField :: EntityField n (PersistEntityGraphSelector n e) + +class PersistEntityGraphSelect n e => PersistEntityGraphNumbered n e where + numberParam :: n -> Int + numberField :: EntityField n Int + uniqueNode :: PersistEntityGraphSelector n e -> Int -> Unique n diff --git a/src/Vervis/Model.hs b/src/Vervis/Model.hs index 63467f0..ccab504 100644 --- a/src/Vervis/Model.hs +++ b/src/Vervis/Model.hs @@ -56,8 +56,17 @@ instance Hashable ProjectRoleId where hash = hash . fromSqlKey instance PersistEntityGraph Ticket TicketDependency where - type PersistEntityGraphSelector Ticket TicketDependency = ProjectId sourceParam = ticketDependencyParent sourceField = TicketDependencyParent destParam = ticketDependencyChild destField = TicketDependencyChild + +instance PersistEntityGraphSelect Ticket TicketDependency where + type PersistEntityGraphSelector Ticket TicketDependency = ProjectId + selectorParam = ticketProject + selectorField = TicketProject + +instance PersistEntityGraphNumbered Ticket TicketDependency where + numberParam = ticketNumber + numberField = TicketNumber + uniqueNode = UniqueTicket