#1 2020-11-15 09:22:10

AOG
Member
Registered: 2014-02-24
Posts: 490

DDD object flattening

Hi Ab,
I have a (feature) request (if needed). My projects now use DDD. For storing product information.

TProduct = class(TSynAutoCreateFields)
  protected
    fProductCode : RawUTF8;
    fDetail      : TDetails;
  published
    property ProductCode  : RawUTF8 read fProductCode write fProductCode;
    property Detail       : TDetails read fDetail;
end;
TDetails = class(TPersistent)
...
end;

The TDetails are flattened by default. But I would like to have them more compact as JSON in the database file.
I succeeded in doing so by disabling the "pilSubClassesFlattening" options in mORMotDDD.pas (and adding an autocreated TDetails-field in the record and with RegisterClassForJSON for TDetails).
Could this be made info an options to flatten by default or not in special cases ? Or can this already be accomplished ?
Thanks.

Edit:
Perhaps an idea: scan the ORM instance for a field with the same signature (and name) as the field in the aggregate itself.

Last edited by AOG (2020-11-15 10:32:28)

Offline

#2 2020-11-15 19:45:53

trx
Member
Registered: 2015-08-30
Posts: 30

Re: DDD object flattening

Hi,

You can exclude the pilSubClassesFlattening flag by overriding TDDDRepositoryRestFactory.GetAggregateRTTIOptions.
I wanted to do the same, so a virtual method was introduced for that purpose. See: https://github.com/synopse/mORMot/pull/179

Last edited by trx (2020-11-15 19:50:25)

Offline

#3 2020-11-15 19:59:40

AOG
Member
Registered: 2014-02-24
Posts: 490

Re: DDD object flattening

Thanks very much. Will look into this. I guess this will serve my needs.

Offline

Board footer

Powered by FluxBB