Skip to content

Commit

Permalink
Always create SymbolToField for "id"
Browse files Browse the repository at this point in the history
- given there is always a {EntityName}Id type
  • Loading branch information
hw202207 committed Jun 28, 2023
1 parent 2a26141 commit 17cbadb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
6 changes: 1 addition & 5 deletions persistent/Database/Persist/TH.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2980,11 +2980,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"
Expand Down
38 changes: 24 additions & 14 deletions persistent/test/Database/Persist/TH/OverloadedLabelSpec.hs
Original file line number Diff line number Diff line change
@@ -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|

Expand All @@ -33,6 +33,10 @@ Dog
Organization
name String

Student
userId UserId
departmentName String
Primary userId
|]

spec :: Spec
Expand Down Expand Up @@ -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 ()

0 comments on commit 17cbadb

Please sign in to comment.