#1 2013-11-19 14:50:59

daniel.tsviatkov
Member
Registered: 2013-11-19
Posts: 2

mORMot ORM questions

Greetings,

I am trying to figure out how the ORM part of the framework is working, but no luck until now, so I decided to give it a try here.
Lets say I have a "model" which should reflect a row in the table "city" of the database.

City = class(TSQLRecord)

And some DB connection properties (in my case ZEOS)

Properties := TSQLDBZEOSConnectionProperties.Create(/*connection string*/);

How I can:
# retrieve in local variable of type City the record with ID 1
# retrieve in local variable of type City the record with name = 'new york'
# retrieve in local variable of type Array[City] where ID between 10 and 15

And lets assume we have a BELONGS_TO relation to another "model" country via country_id FK:
How I can:
# retrieve in local variable of type Array[City] where country.name = 'us';
# eager load in load variable of type Array[City] with their corresponding Country "models"
# create new record in "country" table with 2 related records in "city" table at once. (not single insert, but for example in other framework of another language i would use countryModel.Save( with related );

Thanks in advance!
Best Regards,
Daniel Tsviatkov

Offline

#2 2013-11-19 15:07:07

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

Re: mORMot ORM questions

Take a look at the SAD 1.18 pdf (not the 1.17), and the beginning of the ORM section.

You have a WHERE clause in most ORM methods, to search for a given ID or name.
Take a look at how we handle parameters, e.g:

  MyCity := City.Create(RestClient,myID);
  MyCity := City.Create(RestClient,'name=?',['new york']);
  MyCity := City.Create(RestClient,'id>=? and id<=?',[10,15]);

and so on...

Offline

#3 2013-11-19 15:11:55

daniel.tsviatkov
Member
Registered: 2013-11-19
Posts: 2

Re: mORMot ORM questions

Hey, thanks for the fast answer. I think i wasn't clear enough as seeing your answer.
I am reading the 1.18 SAD documentation, but I can't understand how to tell the RestClient to use my connection properties?
Gluing of all the parts is the current problem in front of me ><

Can you point me to a page where I can see sample constructions.

Best Regards,
Daniel Tsviatkov

Offline

#4 2013-11-19 15:23:48

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

Re: mORMot ORM questions

You need to register your tables as external tables.
See VirtualTableExternalRegister() in mORMotDB.pas.
And there is a whole part of the SAD pdf dealing of it. Search for "VirtualTableExternalRegister" in the SAD keyword index - and chapter "9. External Database Access" (especially paragraph "9.3 ORM Integration").

Offline

Board footer

Powered by FluxBB