Fetch 2 relationship one time

Forum for posting problems using QxOrm library

Fetch 2 relationship one time

Postby behtgod » Sun Jul 31, 2016 3:04 pm

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?
behtgod
 
Posts: 18
Joined: Mon Nov 16, 2015 8:21 am

Re: Fetch 2 relationship one time

Postby qxorm » Mon Aug 01, 2016 7:39 am

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);
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am

Re: Fetch 2 relationship one time

Postby behtgod » Mon Aug 01, 2016 9:29 am

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);
behtgod
 
Posts: 18
Joined: Mon Nov 16, 2015 8:21 am


Return to QxOrm - Help

Who is online

Users browsing this forum: No registered users and 4 guests

cron