Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL types are wrong for shared primary keys #1147

Closed
parsonsmatt opened this issue Oct 31, 2020 · 0 comments · Fixed by #1148
Closed

SQL types are wrong for shared primary keys #1147

parsonsmatt opened this issue Oct 31, 2020 · 0 comments · Fixed by #1148

Comments

@parsonsmatt
Copy link
Collaborator

This module demonstrates the problem.

{-# LANGUAGE TypeApplications, DeriveGeneric #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE StandaloneDeriving #-}

module SharedPrimaryKeyTest where

import TemplateTestImports

import Database.Persist
import Database.Persist.Sql
import Database.Persist.Sql.Util
import Database.Persist.TH

share [ mkPersist sqlSettings ] [persistLowerCase|

User
    name    String

Profile
    Id      UserId
    email   String

|]

specs :: Spec
specs = describe "Shared Primary Keys" $ do

As of now, this doesn't even compile.

/home/matt/Projects/persistent/persistent-template/test/SharedPrimaryKeyTest.hs:23:51: error:
    • Not in scope: type constructor or class ‘UserId’
    • In the quasi-quotation:
        [persistLowerCase|
            
User        
    name    String
            
Profile     
    Id      UserId
    email   String
            
|]          
   |        
23 | share [ mkPersist sqlSettings ] [persistLowerCase|
   |                                                   ^...
   

Switching Profile to using a userId UserId; Primary userId works. But that's pretty weird, I'd except UserId to have the same resolution with Id as it would for userId.

You can get Clever by doing a (Key User) instead. Then the PersistFieldSql is right, but the actual entityId on the field definition is wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant