Page 1 of 1

I can't understand the insert_with_all_relation

PostPosted: Sat Jan 21, 2012 9:44 am
by magicu
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?

Re: I can't understand the insert_with_all_relation

PostPosted: Sat Jan 21, 2012 10:11 am
by QxOrm admin
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

Re: I can't understand the insert_with_all_relation

PostPosted: Sat Jan 21, 2012 10:27 am
by magicu
I got it, thank you very much. ;)