Skip to content

Commit 29ec833

Browse files
committed
fix comment
1 parent cd25558 commit 29ec833

1 file changed

Lines changed: 57 additions & 7 deletions

File tree

persistent/Database/Persist/TH/Internal.hs

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,9 @@ fixEntityDef ued =
10571057
filter isHaskellUnboundField (unboundEntityFields ued)
10581058
}
10591059

1060-
-- | Settings to be passed to the 'mkPersist' function.
1060+
-- | Settings that can be passed to the 'mkPersist' (mps) function to control what code is generated.
1061+
-- This is (just) the data type definition, so you will most likely want to use and adapt concrete values
1062+
-- like 'sqlSettings'.
10611063
data MkPersistSettings = MkPersistSettings
10621064
{ mpsBackend :: Type
10631065
-- ^ Which database backend we\'re using. This type is used for the
@@ -1083,15 +1085,63 @@ data MkPersistSettings = MkPersistSettings
10831085
, mpsPrefixFields :: Bool
10841086
-- ^ Prefix field names with the model name. Default: True.
10851087
--
1086-
-- Note: this field is deprecated. Use the mpsFieldLabelModifier and
1088+
-- Note: this field is deprecated. Use the 'mpsFieldLabelModifier' and
10871089
-- 'mpsConstraintLabelModifier' instead.
10881090
, mpsFieldLabelModifier :: Text -> Text -> Text
1089-
-- ^ Customise the field accessors and lens names using the entity and field
1090-
-- name. Both arguments are upper cased.
1091+
-- ^ Customise the field names (and lens names) for generated entity data types.
10911092
--
1092-
-- Default: appends entity and field.
1093+
-- Default: appends entity name and field name, equivalent to
10931094
--
1094-
-- Note: this setting is ignored if mpsPrefixFields is set to False.
1095+
-- @
1096+
-- mpsFieldLabelModifier = \\entityName fieldName -> entityName <> fieldName
1097+
-- @
1098+
--
1099+
-- to avoid duplicate record field collisions.
1100+
--
1101+
-- For example, with default 'sqlSettings' and
1102+
--
1103+
-- @
1104+
-- 'mkPersistWith' 'sqlSettings' [] ['persistLowerCase'|
1105+
-- Person
1106+
-- name Text
1107+
-- age Int
1108+
-- |]
1109+
-- @
1110+
--
1111+
-- it will generate the entity data type
1112+
--
1113+
-- @
1114+
-- Person {
1115+
-- personName :: Text, -- generated field name
1116+
-- personAge :: Int -- generated field name
1117+
-- }
1118+
-- @
1119+
--
1120+
-- Note: this setting is ignored if the deprecated 'mpsPrefixFields' is set to False.
1121+
--
1122+
-- === __Example without entity name__
1123+
--
1124+
-- You may not want the entity name prefix for all fields, so use
1125+
--
1126+
-- @
1127+
-- 'mkPersistWith' ('sqlSettings' { mpsFieldLabelModifier = \\\_entityName fieldName -> fieldName }) [] ['persistLowerCase'|
1128+
-- Person
1129+
-- name Text
1130+
-- age Int
1131+
-- |]
1132+
-- @
1133+
--
1134+
-- instead. This will generate the entity data type
1135+
--
1136+
-- @
1137+
-- Person {
1138+
-- name :: Text,
1139+
-- age :: Int
1140+
-- }
1141+
-- @
1142+
--
1143+
-- When you have multiple entites with the same field name, you might need to
1144+
-- add @{-# LANGUAGE DuplicateRecordFields #-}@ for your code to compile.
10951145
--
10961146
-- @since 2.11.0.0
10971147
, mpsAvoidHsKeyword :: Text -> Text
@@ -1106,7 +1156,7 @@ data MkPersistSettings = MkPersistSettings
11061156
--
11071157
-- Default: appends entity and field
11081158
--
1109-
-- Note: this setting is ignored if mpsPrefixFields is set to False.
1159+
-- Note: this setting is ignored if the deprecated 'mpsPrefixFields' is set to False.
11101160
--
11111161
-- @since 2.11.0.0
11121162
, mpsEntityHaddocks :: Bool

0 commit comments

Comments
 (0)