#1 2017-08-27 07:32:15

mhmda
Member
Registered: 2017-03-01
Posts: 19

DDD & Aggregate first example

Hello,

I'm reading the book of Erick about mORMot trying to understand the conecept of the ORM/DDD/Aggregate: I understand that is doesn't 'join' table as I thought firstly but it's technology or a way for representing your data as DDD/ORM.

Erick show an example in page 183 but when I run that code the 'pTree' field in 'plant' table is 'bigint' not json as showed in Erick book, can someone tell why?

tree.png

Erick's table:
tree3.png

Erick says : "The descendant classes are technically stored as JSON, and when you read them, they are retrieved and de-serialized back to the structured format."

TTree = class(TSQLRecord)
  private
    fnumTreeHouses: integer;
    frequireleafpickup: TDate;
  published
    property tNumTreeHouses: integer read fnumTreeHouses write fnumTreeHouses;
    property trequireleafpickup: TDate read frequireleafpickup write frequireleafpickup;
end;

TPlant = class(TSQLRecord)
  private
    fType: RawUTF8;
    fheight: integer; // cm or inches
    fleafcolor: integer;
    fTree : TTree;
  published
    property pType: RawUTF8 index 20 read fType write fType stored AS_UNIQUE;
    property pHeight: integer read fheight write fheight;
    property pLeafColor: integer read fleafcolor  write fleafcolor;
    property pTree : TTree read ftree write ftree;
end;
....
Plant, plant2 : TPlant;
aServerName:= TSQLDBZeosConnectionProperties.URI(dMySQL,aRawServerName);
Model:=       TSQLModel.Create([TTree,TPlant],ROOT_NAME);
props:=propsClass.Create(aServerName,aDatabaseName,aUserID,aPassword);

VirtualTableExternalRegister(Model,TPlant,props);
VirtualTableExternalRegister(Model,TTree,props);

// save aggregate root
plant := TPlant.Create(DB,'');
plant.pType := 'oak';
plant.pTree := TTree.Create;
plant.pTree.fnumTreeHouses := 1;
plant.pTree.frequireleafpickup := now;
DB.Add( plant, True);
plant.pTree.Free;
plant.Free;

Last edited by mhmda (2017-08-27 08:59:07)

Offline

#2 2017-08-27 21:00:03

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,240
Website

Re: DDD & Aggregate first example

If the property is a TSqlRecord it will be stored as integer.
If the property is a persistent class, it will be stored as serialized json.

Offline

#3 2017-08-28 05:36:45

mhmda
Member
Registered: 2017-03-01
Posts: 19

Re: DDD & Aggregate first example

I understand now, Thank you ab and I think Erick should correct that in his book.

Offline

Board footer

Powered by FluxBB