Missing OnInserted execution

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:

  1. there are no Items created, TLogEntity will not writen
  2. 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?

Are you able to provide a project reproducing the issue using the mentioned mapped classes and events?

sample_project_CachedOnUpdated.zip (9.1 KB)

Thanks a lot. We were able to identify the problem and fix it. Next version will include the fix.

So is there a quick fix, that I can implement until next version will be released?

I will send you a private message with instructions.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.