how to get the count of child records without get objects

Forum for posting problems using QxOrm library

how to get the count of child records without get objects

Postby Guest » Thu Feb 09, 2012 4:18 am

If I get a parent record, how to get the count of child records without get all children objects, because it's to slow. I only want get the count in one query.
Guest
 

Re: how to get the count of child records without get objects

Postby QxOrm admin » Thu Feb 09, 2012 8:24 am

Hi,

If you fetch your parent and then get children count, you can write something like this :
Code: Select all
MyParent parent; parent.setId(50);
QSqlError daoError = qx::dao::fetch_by_id(parent);
long lChildCount = qx::dao::count<MyChild>(qx_query().where("parent_id").isEqualTo(parent.getId()));
QxOrm admin
 


Return to QxOrm - Help

Who is online

Users browsing this forum: No registered users and 5 guests