#1 2012-10-31 11:21:40

lele9
Member
Registered: 2011-10-28
Posts: 170

TSQLRecord, retrieve "complete" object

Hi,
i see that when i retrieve a TSQLRecord object if one property is TSQLRecord too, i have just the ID.

for example
i have TSQLComune = class(TSQLRecord) with two properties Nome: String; and Provincia: TSQLProvincia;
so when i retrieve a TSQLComune object in Provincia i have just the ID of TSQLProvincia object.

and its ok.

but in some case i would like to retrieve a complete object.

for example
objectTSQLComune := retrieveComplete(TSQLComune, ID);
and in objectTSQLComune.Provincia have the object, not the ID.

this because in some case i would like to pass my object to other class that can access all properties, but i wont that know orm function!

Its possible? How?

Thanks,
Emanuele.

Offline

#2 2012-11-01 10:30:02

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

Re: TSQLRecord, retrieve "complete" object

This is not handled directly.

What you can do easily is to add another not published variable, in which you store the instance, like ProvinciaInstance: TSQLProvincia.
There is

constructor TSQLRecord.Create(aClient: TSQLRest; aPublishedRecord: TSQLRecord; ForUpdate: boolean);

to retrieve an instance of the class directly for the "Provincia" record. Or you can use the TSQLProvincia.ID getter which will detect it is a pseudo-instance.

Offline

#3 2012-11-05 09:18:34

lele9
Member
Registered: 2011-10-28
Posts: 170

Re: TSQLRecord, retrieve "complete" object

hi ab,
i think that use a non published variable to store the instance break data consistency because i can update an object (i.e. Provincia) so i should update all instance stored in other object.
I think to use a getter for Provincia ID but i must pass a TSQLRest Instance so the getter isn't automatic...
what do you think?
Emanuele.

Offline

#4 2012-11-05 09:43:00

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

Re: TSQLRecord, retrieve "complete" object

You are discovering the issue about "lazy loading" in ORM.
See http://en.wikipedia.org/wiki/Lazy_loading

This is a nightmare of use, in some cases.
Your program may become slow because it loads too much information from the DB, or you may loose information since you may not retrieve lazy members but thought they were...

In mORMot, scheme is pretty basic, but also complete:

1. There is no lazy loading, unless you make an explicit many to many JOIN query.
http://blog.synopse.info/post/2011/12/0 … JOIN-query
This is by design, in order to achieve best performance, and always consistent data retrieval.

2. You should use value-object / data sharding patterns, not be limited to the RDBMS-oriented JOIN feature.
http://blog.synopse.info/post/2011/07/0 … chitecture
That is, you are encouraged to use dynamic arrays to store your value-objects or entities into your aggregate root objects.
As stated by the domain driven design pattern: "Repositories Save and Dispense Aggregate Roots".
http://msdn.microsoft.com/en-us/magazine/dd419654.aspx

About the general design lying under mORMot, see http://blog.synopse.info/post/2012/07/1 … e-them-all
Framework documentation already comments abundantly about those design choices.

Offline

#5 2012-11-05 12:02:03

lele9
Member
Registered: 2011-10-28
Posts: 170

Re: TSQLRecord, retrieve "complete" object

I see the documentation and i think that lazy loading its perfect, but there are some cases where i need that the object is all initialized.
Its possible to add a method in the orm to do this?
this can help just me?anybody have this necessity?

Offline

Board footer

Powered by FluxBB