I have some entities like that:
TLogEntity = class
private
FId: TGUID;
FLogEntry: string;
// ...
end;
TItem = class;
TParent = class
private
FId: TGUID;
[ManyValuedAssociation([TAssociationProp.Lazy], CascadeTypeAllRemoveOrphan, 'FParent'), OrderBy(csSortPos)]
FItems: Proxy<TList<TItem>>;
protected
[OnInserted]
procedure OnInserted(aArgs: TInsertedArgs);
// ...
end;
TItem = class
private
FId: TGUID;
FSortPos: Integer;
[Association([TAssociationProp.Lazy], [TCascadeType.Refresh, TCascadeType.Evict])]
FParent: Proxy<TParent>;
// ...
end;
procedure TParent.OnInserted(aArgs: TInsertedArgs);
var
hLog: TLogEntity;
begin
hLog := TLogEntity.Create;
hLog.LogEntry := FId.ToString + ' created';
TObjectManager(aArgs.Manager).SaveOrUpdate(hLog);
end;
Creating new TParent Data will also create TLogEntity Data.
If CachedUpdates is active:
- there are no Items created, TLogEntity will not writen
- at least one Item attached to TParent, TLogEntity will be written
If CachedUpdates is not active TLogEntity will be written in every case.
This example does not write TLogEntity:
hObjMan.CachedUpdates := True; // disabling CachedUpdates would write TLogEntity...
hParent := TParent.Create;
hObjMan.SaveOrUpdate(hParent);
hObjMan.ApplyUpdates;
This example does write TLogEntity:
hObjMan.CachedUpdates := True;
hParent := TParent.Create;
hItem := TItem.Create;
hParent.Items.Add(hItem);
hItem.SortPos := hParent.Items.IndexOf(hItem);
hObjMan.SaveOrUpdate(hParent);
hObjMan.ApplyUpdates;
I think this should behave the same way, never mind if hParent has Items or not.
How can I fix in a manual way?