@@ -1053,7 +1053,9 @@ fixEntityDef ued =
10531053 filter isHaskellUnboundField (unboundEntityFields ued)
10541054 }
10551055
1056- -- | Settings to be passed to the 'mkPersist' function.
1056+ -- | Settings that can be passed to the 'mkPersist' (mps) function to control what code is generated.
1057+ -- This is (just) the data type definition, so you will most likely want to use and adapt concrete values
1058+ -- like 'sqlSettings'.
10571059data MkPersistSettings = MkPersistSettings
10581060 { mpsBackend :: Type
10591061 -- ^ Which database backend we\'re using. This type is used for the
@@ -1079,15 +1081,63 @@ data MkPersistSettings = MkPersistSettings
10791081 , mpsPrefixFields :: Bool
10801082 -- ^ Prefix field names with the model name. Default: True.
10811083 --
1082- -- Note: this field is deprecated. Use the mpsFieldLabelModifier and
1084+ -- Note: this field is deprecated. Use the ' mpsFieldLabelModifier' and
10831085 -- 'mpsConstraintLabelModifier' instead.
10841086 , mpsFieldLabelModifier :: Text -> Text -> Text
1085- -- ^ Customise the field accessors and lens names using the entity and field
1086- -- name. Both arguments are upper cased.
1087+ -- ^ Customise the field names (and lens names) for generated entity data types.
10871088 --
1088- -- Default: appends entity and field.
1089+ -- Default: appends entity name and field name, equivalent to
10891090 --
1090- -- Note: this setting is ignored if mpsPrefixFields is set to False.
1091+ -- @
1092+ -- mpsFieldLabelModifier = \\entityName fieldName -> entityName <> fieldName
1093+ -- @
1094+ --
1095+ -- to avoid duplicate record field collisions.
1096+ --
1097+ -- For example, with default 'sqlSettings' and
1098+ --
1099+ -- @
1100+ -- 'mkPersistWith' 'sqlSettings' [] ['persistLowerCase'|
1101+ -- Person
1102+ -- name Text
1103+ -- age Int
1104+ -- | ]
1105+ -- @
1106+ --
1107+ -- it will generate the entity data type
1108+ --
1109+ -- @
1110+ -- Person {
1111+ -- personName :: Text, -- generated field name
1112+ -- personAge :: Int -- generated field name
1113+ -- }
1114+ -- @
1115+ --
1116+ -- Note: this setting is ignored if the deprecated 'mpsPrefixFields' is set to False.
1117+ --
1118+ -- === __Example without entity name__
1119+ --
1120+ -- You may not want the entity name prefix for all fields, so use
1121+ --
1122+ -- @
1123+ -- 'mkPersistWith' ('sqlSettings' { mpsFieldLabelModifier = \\\_entityName fieldName -> fieldName }) [] ['persistLowerCase'|
1124+ -- Person
1125+ -- name Text
1126+ -- age Int
1127+ -- | ]
1128+ -- @
1129+ --
1130+ -- instead. This will generate the entity data type
1131+ --
1132+ -- @
1133+ -- Person {
1134+ -- name :: Text,
1135+ -- age :: Int
1136+ -- }
1137+ -- @
1138+ --
1139+ -- When you have multiple entites with the same field name, you might need to
1140+ -- add @{-# LANGUAGE DuplicateRecordFields #-}@ for your code to compile.
10911141 --
10921142 -- @since 2.11.0.0
10931143 , mpsAvoidHsKeyword :: Text -> Text
@@ -1102,7 +1152,7 @@ data MkPersistSettings = MkPersistSettings
11021152 --
11031153 -- Default: appends entity and field
11041154 --
1105- -- Note: this setting is ignored if mpsPrefixFields is set to False.
1155+ -- Note: this setting is ignored if the deprecated ' mpsPrefixFields' is set to False.
11061156 --
11071157 -- @since 2.11.0.0
11081158 , mpsEntityHaddocks :: Bool
0 commit comments