Page 1 of 1

how to get the count of child records without get objects

PostPosted: Thu Feb 09, 2012 4:18 am
by Guest
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.

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

PostPosted: Thu Feb 09, 2012 8:24 am
by QxOrm admin
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()));