For instance, the following class
definition will create an
index for its SerialNumber
property (up to 30 characters long if
stored in an external database), and will expect a link to a model of diaper
(TSQLDiaperModel
) and the baby which used it
(TSQLBaby
).
An ID
/ RowID
column will always be available (from
TSQLRecord
), so in this case, you would be able to make a
fast look-up for a particular diaper from either its internal
mORmot ID, or its official unique serial number:
/// table used for the Diaper queries
TSQLDiaper = class(TSQLRecord)
private
fSerialNumber: RawUTF8;
fModel: TSQLDiaperModel;
fBaby: TSQLBaby;
published
property SerialNumber: RawUTF8 index 30 read fSerialNumber write fSerialNumber
stored AS_UNIQUE;
property Model: TSQLDiaperModel read fModel write fModel;
property Baby: TSQLBaby read fBaby write fBaby;
end;
Just a constant definition, and code sounds more readable.
It is worth saying that Delphi SOAP units uses a similar trick, by defining
stored AS_ATTRIBUTE
in its TRemotable
classes.