You are not logged in.
Pages: 1
Are arrays or lists supported as property types for ddd podos? (the TDomUser example doesn't use them)
Offline
TDDDRepositoryRestFactory.ComputeSQLRecord is a very handy function. It does the mapping from pure DDD-Objects to ORM-Objects.
But with T*ObjArray seems to be problem. For example:
TDetails = class(TPersistent)
private
fName: RawUTF8;
published
property Name: RawUTF8 read fName write fName;
end;
TDetailsObjArray = array of TDetails;
TMaster = class(TSynAutoCreateFields)
private
fName: RawUTF8;
fDetails: TDetailsObjArray;
published
property Name: RawUTF8 read fName write fName;
property Details: TDetailsObjArray read fDetails write fDetails;
end;
initialization
TJSONSerializer.RegisterObjArrayForJSON(TypeInfo(TDetailsObjArray), TDetails);
The generated ORM-Object would look like
type
/// ORM class corresponding to TMaster DDD aggregate
TSQLRecordMaster = class(TSQLRecord)
protected
fName: RawUTF8; // RawUTF8
fDetails: variant; // TDetailsObjArray
published
/// maps TMaster.Name
property Name: RawUTF8 read fName write fName;
/// maps TMaster.Details
property Details: variant read fDetails write fDetails;
end;
The Details variant type becomes a TEXT column in SQLite: CREATE TABLE Master(..., Details TEXT COLLATE NOCASE);
But when creating a TDDDRepositoryRestFactory class there is an exception raised:
TDDDRepositoryRestFactory types do not match at DB level: TMaster.Details:TDetailsObjArray=42746606 and TSQLRecordMaster.Details:Variant=55746606
Right: aggregate SQLDBFieldType (sftBlobDynArray) isn't equal to record SQLDBFieldType (sftVariant).
By manual patching the generated TSQLRecord class to this, all the stuff is working fine:
type
/// ORM class corresponding to TMaster DDD aggregate
TSQLRecordMaster = class(TSQLRecord)
protected
fName: RawUTF8; // RawUTF8
fDetails: TDetailsObjArray; // TDetailsObjArray
published
/// maps TMaster.Name
property Name: RawUTF8 read fName write fName;
/// maps TMaster.Details
property Details: TDetailsObjArray read fDetails write fDetails;
end;
The corresponding TDetailsObjArray type becomes a BLOB column in SQLite: CREATE TABLE Master(..., Details BLOB);
Is it possible to compute T*ObjArray-Properties to appropriate types, or is there another solution?
Offline
Please try http://synopse.info/fossil/info/f40b6aa628
(not fully tested, though)
Offline
Thank you for the patch! It works like a charm
It should be noted that in SQLite the variant Details becomes a BLOB column (before the patch it was a TEXT column).
Offline
sorry, my mistake: The column type is TEXT as before. My DCU-file was not correctly updated
Offline
DDD now also allows mapping with a RawUTF8 ORM field for T*ObjArray published fields, in addition to default variant type, if the on-the-fly conversion to/from TDocVariant appears to be a bottleneck.
See http://synopse.info/fossil/info/898b225dab
Thanks for the feedback.
Offline
Pages: 1