1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedLabels #-}
{-# LANGUAGE PartialTypeSignatures #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
module Database.Persist.TH.MultiBlockSpec where
import TemplateTestImports
import Database.Persist.TH.MultiBlockSpec.Model
share
[ mkPersistWith sqlSettings importDefList
]
[persistLowerCase|
Thing
name Text
Primary name
ThingAuto
name Text
MBBar
name Text
age Int
user UserId
thing ThingId
thingAuto ThingAutoId
profile MBDogId
Foreign MBCompositePrimary bar_to_comp name age
|]
spec :: Spec
spec = describe "MultiBlockSpec" $ do
describe "MBBar" $ do
let
edef =
entityDef $ Proxy @MBBar
describe "Foreign Key Works" $ do
let
[n, a, userRef, thingRef, thingAutoRef, profileRef] =
getEntityFields edef
it "User reference works" $ do
fieldReference userRef
`shouldBe`
ForeignRef
(EntityNameHS "User")
it "Primary key reference works" $ do
fieldReference profileRef
`shouldBe`
ForeignRef
(EntityNameHS "MBDog")
it "Thing ref works (same block)" $ do
fieldReference thingRef
`shouldBe`
ForeignRef
(EntityNameHS "Thing")
it "ThingAuto ref works (same block)" $ do
fieldReference thingAutoRef
`shouldBe`
ForeignRef
(EntityNameHS "ThingAuto")
|