Using oneToMany in queries

Forum for posting problems using QxOrm library

Using oneToMany in queries

Postby gianks » Sat Aug 13, 2016 8:29 pm

Hi all,
i have what i think is a basic need: select rows using the HAVING statement after a LEFT OUTER JOIN using the COUNT(*).

I wish to select all the lines from a table which are referred a certain number of times from another one, ex: query.where("relation_one_to_many = 0").

How can i do this?
Thanks
gianks
 
Posts: 45
Joined: Mon Jul 04, 2016 1:04 pm

Re: Using oneToMany in queries

Postby qxorm » Tue Aug 16, 2016 7:45 am

Hello,

Sorry I don't understand, could you please give an example ?
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am

Re: Using oneToMany in queries

Postby gianks » Mon Aug 22, 2016 7:55 pm

Off course:
Code: Select all
SELECT A.id, count(B.default_A_id) as cnt FROM A  LEFT OUTER JOIN B on default_A_id = B.id GROUP BY A.id HAVING cnt = 0


I'm using this as a free Query in conjunction with execute_query currently but i think that probably is possible to use the relationship in a standard query like:

qx::QxSqlQuery query;
query.where(" count (A.Bs )").equalsTo(0);

Supposing that Bs is a N-1 relationship defined in A using default_A_id as the FK column.
gianks
 
Posts: 45
Joined: Mon Jul 04, 2016 1:04 pm

Re: Using oneToMany in queries

Postby qxorm » Tue Aug 23, 2016 10:00 am

I'm using this as a free Query in conjunction with execute_query

Yes, you have to do that because qx::QxSqlQuery class doesn't support it.
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am

Re: Using oneToMany in queries

Postby gianks » Tue Aug 23, 2016 3:14 pm

Perfect, the important part for me was to accomplish this in a nice/compilant way.
If that is, i have no complains since with a little of manual writing i obtained in two line of codes an array of objects filled as needed 8-)

Thanks again for all the clarifications and support, this is making QxOrm a must-have in C++ projects IMHO.

Best regards
gianks
 
Posts: 45
Joined: Mon Jul 04, 2016 1:04 pm

Re: Using oneToMany in queries

Postby qxorm » Wed Aug 24, 2016 7:26 am

this is making QxOrm a must-have in C++ projects IMHO

Thx !
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am


Return to QxOrm - Help

Who is online

Users browsing this forum: No registered users and 1 guest

cron