From 82bb9d5597740ec1d4868edaa9caa05adb38c5a4 Mon Sep 17 00:00:00 2001 From: Alberto Valverde Date: Fri, 10 Apr 2015 10:51:45 +0200 Subject: [PATCH] test we can join via non-id primary keys --- test/Test.hs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/Test.hs b/test/Test.hs index b5a643f..572930d 100644 --- a/test/Test.hs +++ b/test/Test.hs @@ -78,6 +78,11 @@ share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistUpperCase| name String Primary name deriving Eq Show + ArticleTag + articleId ArticleId + tagId TagId + Primary articleId tagId + deriving Eq Show Article2 title String frontcoverId FrontcoverId @@ -412,6 +417,27 @@ main = do 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 it "works for a simple example with (==.)" $ run $ do