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