test we can join via non-id primary keys
This commit is contained in:
parent
d3e45964ae
commit
82bb9d5597
26
test/Test.hs
26
test/Test.hs
@ -78,6 +78,11 @@ share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistUpperCase|
|
|||||||
name String
|
name String
|
||||||
Primary name
|
Primary name
|
||||||
deriving Eq Show
|
deriving Eq Show
|
||||||
|
ArticleTag
|
||||||
|
articleId ArticleId
|
||||||
|
tagId TagId
|
||||||
|
Primary articleId tagId
|
||||||
|
deriving Eq Show
|
||||||
Article2
|
Article2
|
||||||
title String
|
title String
|
||||||
frontcoverId FrontcoverId
|
frontcoverId FrontcoverId
|
||||||
@ -412,6 +417,27 @@ main = do
|
|||||||
pPk `shouldBe` thePk
|
pPk `shouldBe` thePk
|
||||||
-}
|
-}
|
||||||
|
|
||||||
|
it "works when joining via a non-id primary key" $
|
||||||
|
run $ do
|
||||||
|
let fc = Frontcover number ""
|
||||||
|
article = Article "Esqueleto supports composite pks!" number
|
||||||
|
tag = Tag "foo"
|
||||||
|
otherTag = Tag "ignored"
|
||||||
|
number = 101
|
||||||
|
insert_ fc
|
||||||
|
insert_ otherTag
|
||||||
|
artId <- insert article
|
||||||
|
tagId <- insert tag
|
||||||
|
insert_ $ ArticleTag artId tagId
|
||||||
|
[(Entity _ retArt, Entity _ retTag)] <- select $
|
||||||
|
from $ \(a `InnerJoin` at `InnerJoin` t) -> do
|
||||||
|
on (t^.TagId ==. at^.ArticleTagTagId)
|
||||||
|
on (a^.ArticleId ==. at^.ArticleTagArticleId)
|
||||||
|
return (a, t)
|
||||||
|
liftIO $ do
|
||||||
|
retArt `shouldBe` article
|
||||||
|
retTag `shouldBe` tag
|
||||||
|
|
||||||
describe "select/where_" $ do
|
describe "select/where_" $ do
|
||||||
it "works for a simple example with (==.)" $
|
it "works for a simple example with (==.)" $
|
||||||
run $ do
|
run $ do
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user