Page 1 of 1

Using oneToMany in queries

PostPosted: Sat Aug 13, 2016 8:29 pm
by gianks
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

Re: Using oneToMany in queries

PostPosted: Tue Aug 16, 2016 7:45 am
by qxorm
Hello,

Sorry I don't understand, could you please give an example ?

Re: Using oneToMany in queries

PostPosted: Mon Aug 22, 2016 7:55 pm
by gianks
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.

Re: Using oneToMany in queries

PostPosted: Tue Aug 23, 2016 10:00 am
by qxorm
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.

Re: Using oneToMany in queries

PostPosted: Tue Aug 23, 2016 3:14 pm
by gianks
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

Re: Using oneToMany in queries

PostPosted: Wed Aug 24, 2016 7:26 am
by qxorm
this is making QxOrm a must-have in C++ projects IMHO

Thx !