This example changes the cascade parameter of many-valued association attribute. It identifies the many-valued association by the name of the generated private field (FEmployeesList) in a specific class (TEmployees):
procedure OnManyValuedAssociationGenerated(Args: TManyValuedAssociationGeneratedArgs);
begin
case Args.CodeType.Name of
'TEmployees':
case Args.Field.Name of
'FEmployeesList':
TCodeSnippetExpression(Args.AssociationAttr.Arguments[1].Value).Value := 'CascadeTypeAllRemoveOrphan';
end;
end;
end;
Suppose the original generated source code was this one:
[ManyValuedAssociation([TAssociationProp.Lazy], [TCascadeType.SaveUpdate, TCascadeType.Merge], 'FReportsTo')]
FEmployeesList: Proxy<TList<TEmployees>>;
With the script above, it will become this:
[ManyValuedAssociation([TAssociationProp.Lazy], CascadeTypeAllRemoveOrphan, 'FReportsTo')]
FEmployeesList: Proxy<TList<TEmployees>>;