Page 1 of 1

Fetch 2 relationship one time

PostPosted: Sun Jul 31, 2016 3:04 pm
by behtgod
There are 3 table.
____________
t_a
----------------|
id
b_id
============
t_b
----------------|
id
c_id
============
t_c
----------------|
id
----------------
and corresponding classes.

I defined two many-to-one relationship.
First one between t_a.b_id and t_b.id,and the second one between t_b.c_id and t_c.
I tried fetch t_a by id with all relationship(use qx::dao::fetch_by_query_with_all_relation() method) but only the first relationship works.
I found only "LEFT OUTER JOIN t_b" in sql.
Could I fetch with both relationship one time?

Re: Fetch 2 relationship one time

PostPosted: Mon Aug 01, 2016 7:39 am
by qxorm
Hello,

Could I fetch with both relationship one time?

Yes it is possible, it is explained in the QxOrm manual here : https://www.qxorm.com/qxorm_en/manual.html#manual_3840

FYI, qx::dao::fetch_by_id_with_all_relation() function just fetch 1 level of relationship.
So if you want to fetch several levels of relationships, you must use qx::dao::fetch_by_id_with_relation() and define the relationships you want to fetch :
- "*" keyword means "fetch all relationships defined in qx::register_class<T> function (1 level of relationships)" ;
- "->" keyword means "LEFT OUTER JOIN" join type between 2 tables ;
- ">>" keyword means "INNER JOIN" join type between 2 tables.

For example (from the manual) :
Code: Select all
blog_ptr my_blog = blog_ptr(new blog(10));
QSqlError daoError = qx::dao::fetch_by_id_with_relation("author_id->list_blog->list_comment", my_blog);

Re: Fetch 2 relationship one time

PostPosted: Mon Aug 01, 2016 9:29 am
by behtgod
Thank you very much! I should have read the manual more carefully.

qxorm wrote:Hello,

Could I fetch with both relationship one time?

Yes it is possible, it is explained in the QxOrm manual here : https://www.qxorm.com/qxorm_en/manual.html#manual_3840

FYI, qx::dao::fetch_by_id_with_all_relation() function just fetch 1 level of relationship.
So if you want to fetch several levels of relationships, you must use qx::dao::fetch_by_id_with_relation() and define the relationships you want to fetch :
- "*" keyword means "fetch all relationships defined in qx::register_class<T> function (1 level of relationships)" ;
- "->" keyword means "LEFT OUTER JOIN" join type between 2 tables ;
- ">>" keyword means "INNER JOIN" join type between 2 tables.

For example (from the manual) :
Code: Select all
blog_ptr my_blog = blog_ptr(new blog(10));
QSqlError daoError = qx::dao::fetch_by_id_with_relation("author_id->list_blog->list_comment", my_blog);