You are not logged in.
Pages: 1
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
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
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
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
Pages: 1