I can't understand the insert_with_all_relation

Forum for posting problems using QxOrm library

I can't understand the insert_with_all_relation

Postby magicu » Sat Jan 21, 2012 9:44 am

I don't quite understand the different between insert_with_all_relation and insert, There is no doc to describe them, Could you give me an example to show the difference?
magicu
 
Posts: 54
Joined: Fri Jan 20, 2012 9:51 am

Re: I can't understand the insert_with_all_relation

Postby QxOrm admin » Sat Jan 21, 2012 10:11 am

From qxBlog tutorial, imagine that you have a blog instance, and this blog contains a list of comments.
To save it into database, you can save first your blog, and then the list of comments, like this :
Code: Select all
daoError = qx::dao::insert(my_blog);
daoError = qx::dao::insert(my_list_of_comments);


Or you can use the 'insert_with_all_relation()' function, and you have only 1 line of code with the same behaviour :
Code: Select all
daoError = qx::dao::insert_with_all_relation(my_blog);


* qx::dao::insert => save only 1 table.
* qx::dao::insert_with_all_relation => save parent table and all its relations.

Moreover, there is an automatic mechanism of commit/rollback if you use insert_with_all_relation() (nothing saved if there is an error during process).
To have a commit/rollback mechanism using insert function, you can use a session (qx::QxSession class), goto here for more details about this feature :
http://www.qxorm.com/qxorm_en/faq.html#faq_170
QxOrm admin
 

Re: I can't understand the insert_with_all_relation

Postby magicu » Sat Jan 21, 2012 10:27 am

I got it, thank you very much. ;)
magicu
 
Posts: 54
Joined: Fri Jan 20, 2012 9:51 am


Return to QxOrm - Help

Who is online

Users browsing this forum: No registered users and 3 guests