Wrong updates with ManyValued in ObjManager.Save


There is one problem with not neede update-queries with TObjectManager.Save(Obj) execute.

Delphi 10.2.2, Aurelius 3.10, FireDAC with PostgreSQL.

Mapping of two classes:
  [Entity, Table('hr_inv.param_value'), Sequence('hr_inv.PV_SEQ'), Id('ID', TIdGenerator.IdentityOrSequence)]
  TPIParamValue = class (TParamValue)
    [Association([TAssociationProp.Lazy], [])]
    [JoinColumn('pi_result_id', [TColumnProp.NoUpdate])]
    fPIResult: Proxy<TPIResult>;
  [Entity, DiscriminatorValue('5')]// inheritance strategy used
  TPIResultParametrized = class (TPIResult)
    [ManyValuedAssociation([TAssociationProp.Lazy], CascadeTypeAllRemoveOrphan, 'fPIResult')]
    fPVs: Proxy<TPIParamValueList>;

When I try to execute ObjManager.Save(APIResult: TPIResultParametrized) and watch to fdmonitor, I see one insert for main object APIResult (it's ok), one insert per each ManyValued-item (it'ok too), and after one update per ManyValued item, which updates only pi_result_id field, which marked as TColumnProp.NoUpdate. 

Why Aurelius run this updates? All inserts executes in 100ms in my test machine, but updates executes about 3 seconds (triggers, indexes, etc...). This field never changes at all, why Aurelius ignore mapping?

This is a normal behavior because after Aurelius saved the parent and children, it needs to update all the collections belonging to the parent. It's a complex task that might involve transient objects, existing objects that belong to no collections, etc..

Actually it's the INSERT that is already an optimization, since several other ORM's actually do not include the foreign key in the INSERT statement, just in the UPDATE.

Having said that, we're glad to inform that we have implemented an extra optimization that will avoid that extra UPDATE when the INSERT for that child had already updated the foreign key. That optimization will be included in the next TMS Aurelius release.

Give me this update,  please!

And another update, that disable delete queries on each manyValued item after delete main item too!

In last question I think understand that prolem in mapping - a I need to delete [TCascadeType.Remove] from CascadeTypeAllRemoveOrphan

The new version is not ready, it needs to be tested, bundled, etc.. You can contact us directly through e-mail and then what can be done is I send you the specific files that have been modified to address this optimization and you use it at your own risk.