#1 2018-01-04 13:10:31

mORMotStudent
Member
Registered: 2018-01-04
Posts: 4

ORM - Collections / List property

I have two classes, which need to be persisted in a database;

say, TFolha and TFolhaEntradas.

example:

TFolhaEntradas = class (TSQLRecord)

published

property example: String;
end;

TFolha = class (TSQLRecord)

published

property FolhaEntradas: TObjectList <TFolhaEntradas>;
end;


I read in the documentation, that mORMmot keeps the OBJECTList as Json, is that correct?

I need that each objects of the TObjectList <TFolhaEntradas> may be stored in the table of the class TFolhaEntradas!

How could it be done?

Last edited by mORMotStudent (2018-01-04 13:11:07)

Offline

#2 2018-01-04 19:29:15

mORMotStudent
Member
Registered: 2018-01-04
Posts: 4

Re: ORM - Collections / List property

I am looking for a good ORM solution to adopt in a new project, and i think mORMot would be a good candidate, but I am looking for some new basic information about it;

This post (https://synopse.info/forum/viewtopic.php?id=1073)
almost answered my question. That post is about ONE to ONE relation.

but how do mORMot deal with a "one to Many" relation? How does it work in the database?

Does it just create a blob with JSON objects, or create real relations in the database?

Thank you

Offline

#3 2018-01-04 20:12:39

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,571
Website

Re: ORM - Collections / List property

Offline

#4 2018-01-08 01:40:24

mORMotStudent
Member
Registered: 2018-01-04
Posts: 4

Re: ORM - Collections / List property

Thank you, for the reply. I just started to read and test this framework;


After reading the section you suggested, I am trying to use the TSQLRecordMany to get the relationship between the two tables; If I am understanding correctly, it uses a pivot table to do it.

I will use here a simple example, what I want is to understand the correct way to get this relationship working;

So I created three classes, to make the tests.

TPerson(TSQLRecord)
TPhone(TSQLRecord) and
TPhones(TSQLRecordMany)


Then I created a published property in TPerson like this:


property Phones: TPhones read FPhones write FPhones; //TPhones is descending from TSQLRecordMany

But when I use this procedure of TPerson:

procedure TPerson.InsertPhone(IDDI,IDDD,INumber : Integer) ;
var phone : TPhone;
begin

   Phone:= TPhone.Create;
   Phone.ddi := Iddi;
   Phone.ddd := Iddd;
   Phone.numero := INumber ;
   
  if Telefones.ManyAdd(Database.client,self.ID,phone.ID,true,nil) then ////This Method ManyAdd is failing, (returning false)

showMessage('Method returned true') else
showMessage('Method returned false');

end;


So, what is the correct way to use it?


======================================

If I use a TObjectList as a property in a TSQLRecord class, I get a blob JSON in the database table, but what I want is each of these objects may be stored inside its own table, and not as a blob field.

Last edited by mORMotStudent (2018-01-08 03:21:43)

Offline

Board footer

Powered by FluxBB