diff --git a/persistent/ChangeLog.md b/persistent/ChangeLog.md index 74787b577..567222fa0 100644 --- a/persistent/ChangeLog.md +++ b/persistent/ChangeLog.md @@ -4,6 +4,8 @@ * [#1503](https://github.com/yesodweb/persistent/pull/1503) * Create Haddocks from entity documentation comments +* [1497](https://github.com/yesodweb/persistent/pull/1497) + * Always generates `SymbolToField "id"` instance ## 2.14.5.2 diff --git a/persistent/Database/Persist/TH.hs b/persistent/Database/Persist/TH.hs index db04e3fb3..2d76e6ce7 100644 --- a/persistent/Database/Persist/TH.hs +++ b/persistent/Database/Persist/TH.hs @@ -3013,11 +3013,7 @@ mkSymbolToFieldInstances mps entityMap (fixEntityDef -> ed) = do mkEntityFieldConstr fieldHaskellName mkInstance fieldNameT fieldTypeT entityFieldConstr - mkey <- - case unboundPrimarySpec ed of - NaturalKey _ -> - pure [] - _ -> do + mkey <- do let fieldHaskellName = FieldNameHS "Id" diff --git a/persistent/test/Database/Persist/TH/OverloadedLabelSpec.hs b/persistent/test/Database/Persist/TH/OverloadedLabelSpec.hs index b81453160..363375ef5 100644 --- a/persistent/test/Database/Persist/TH/OverloadedLabelSpec.hs +++ b/persistent/test/Database/Persist/TH/OverloadedLabelSpec.hs @@ -1,23 +1,23 @@ -{-# LANGUAGE DataKinds #-} -{-# LANGUAGE DerivingStrategies #-} -{-# LANGUAGE FlexibleContexts #-} -{-# LANGUAGE FlexibleInstances #-} -{-# LANGUAGE GADTs #-} +{-# 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 TypeFamilies #-} -{-# LANGUAGE UndecidableInstances #-} +{-# LANGUAGE MultiParamTypeClasses #-} +{-# LANGUAGE OverloadedLabels #-} +{-# LANGUAGE PartialTypeSignatures #-} +{-# LANGUAGE QuasiQuotes #-} +{-# LANGUAGE StandaloneDeriving #-} +{-# LANGUAGE TemplateHaskell #-} +{-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE UndecidableInstances #-} {-# OPTIONS_GHC -Wname-shadowing -Werror=name-shadowing #-} module Database.Persist.TH.OverloadedLabelSpec where -import TemplateTestImports +import TemplateTestImports mkPersist sqlSettings [persistUpperCase| @@ -33,6 +33,10 @@ Dog Organization name String +Student + userId UserId + departmentName String + Primary userId |] spec :: Spec @@ -60,5 +64,11 @@ spec = describe "OverloadedLabels" $ do compiles + it "works for Primary labels" $ do + let StudentId = #id + studentId = #id :: EntityField Student StudentId + + compiles + compiles :: IO () compiles = pure ()