#1 2022-01-25 08:46:39

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 392

Results based on two or three Orm entities

Probably it is stupid but as I am doing my first moves using Mormot2 I have not find a sure way to deal with the following:
I have the following entities:

 TOrmProductSource = class(TOrm)
  private
    Fmoo:rawutf8;
    Fopa:TOrmProductDest;
    Fcount:PtrInt;
  published
    property moo:rawutf8 read Fmoo write Fmoo;
    property opa:TOrmProductDest read Fopa write Fopa;
    property count:PtrInt read Fcount write Fcount;
end;

TOrmProductDest = class(TOrm)
  private
    Ftest:RawUtf8;
    Famount:PtrInt;
  published
    property test:RawUtf8 read Ftest write Ftest;
    property amount:PtrInt read Famount write Famount;
end;

The TOrmProductDest is used by other Torms also and can not be an integrated collection in TOrmProductSource.

I want to retrieve all TOrmProductSource that have a count property of less than 10 and  the opa's amount property with a value of more than 50.
How can I combine these two or more Torms in one request?

Thank you in advance

Last edited by dcoun (2022-01-25 08:51:20)

Offline

#2 2022-01-25 08:52:15

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

Re: Results based on two or three Orm entities

The mORMot 1 documentation still work on this subject.

Just replace TSQLRecord* into TOrm* names. wink

https://synopse.info/files/html/Synopse … ml#TITL_58

Offline

#3 2022-01-25 09:03:44

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 392

Re: Results based on two or three Orm entities

ab wrote:

The mORMot 1 documentation still work on this subject.

Just replace TSQLRecord* into TOrm* names. wink

https://synopse.info/files/html/Synopse … ml#TITL_58


I am a bit lost reading about many2many associations with a separate Torm that holds many to many information.
I have already tables that they are mapped to TOrms and have pointers to other TOrms tables.
Is there a way to use an 'one to many' relationship with the included pointer (Fopa:TOrmProductDest)?
I do not need something complicated. Each Torm has max 2 pointers to other Torms

Last edited by dcoun (2022-01-25 09:04:58)

Offline

#4 2022-01-25 09:36:12

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

Re: Results based on two or three Orm entities

Only the TOrmMany class has the methods to handle joins.

You can just inherit the ORM class which maps the pivot table from TOrmMany instead of plain TOrm.

Offline

#5 2022-01-25 10:42:35

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 392

Re: Results based on two or three Orm entities

ab wrote:

Only the TOrmMany class has the methods to handle joins.

You can just inherit the ORM class which maps the pivot table from TOrmMany instead of plain TOrm.

Understood. not possible without a pivot table. I have to stay with sql queries then. Thanks a lot.

Offline

Board footer

Powered by FluxBB