definition:
|
updateTransaction :: ControllerGenerator
updateTransaction erdname (Entity entityName attrList) _ allEntities =
stCmtFunc
("Transaction to persist modifications of a given " ++ entityName ++
" entity\nto the database.")
(transFunctionName entityName "update")
2 Private
(tupleType ([baseType (model erdname, entityName)] ++
map (\ (name,_) -> listType (ctvar name)) manyToManyEntities)
~> applyTC (dbconn "DBAction") [unitType])
[simpleRule
[tuplePattern
([CPVar (0, lowerFirst entityName)] ++
(map (\ (param, varId) -> CPVar (varId, param))
(zip (map (\ (ename,erel) -> lowerFirst erel ++ ename ++ "s")
manyToManyEntities)
[1..])))
] -- parameter list for controller
(doExpr $
(CSExpr (applyF (model erdname, "update" ++ entityName)
[cvar (lowerFirst entityName)]) :
(concatMap (\ (ename,erel) ->
[CSPat (CPVar (0, "old" ++ erel ++ ename ++ "s"))
(applyF (controllerModuleName entityName,
"get" ++ erel ++ entityName ++ ename ++ "s")
[cvar (lowerFirst entityName)]),
CSExpr (applyF (controllerModuleName entityName,
"remove" ++ erel)
[cvar ("old"++ erel ++ ename ++ "s"),
cvar (lowerFirst entityName)])])
manyToManyEntities
) ++
(map (\ (ename,erel) -> CSExpr $
applyF (controllerModuleName entityName, "add" ++ erel)
[cvar (lowerFirst erel ++ ename ++ "s"),
cvar (lowerFirst entityName)])
manyToManyEntities)
))]
where
manyToManyEntities = manyToMany allEntities (Entity entityName attrList)
|