Page 1 of 1

Can I use an id instead of reference object?

PostPosted: Fri Feb 10, 2012 9:51 am
by magicu
Code: Select all
BlogPtr blogPtr(new Blog);

blogPtr->authorPtrX = authorPtr;
blogPtr->blog_text = "";
blogPtr->....

qx::dao::insert_with_all_relationship(blogPtr);



Do I have to get authorPtr first by another query? It's too slow. Can I use an int id of author instead of authorPtr object?

Re: Can I use an id instead of reference object?

PostPosted: Fri Feb 10, 2012 12:03 pm
by QxOrm admin
If you are sure that your authorPtr already exists into database, I think that you can set only the ID => It would work...

You can also imagine to fetch all authors in your program and then store all of them into the cache.
Then you will not have to fetch your author a second time because it is already in the cache.
And to update your cache each time you make a modif on author table, you can use QxOrm trigger to be sure that your cache is up-to-date.
But there is other ways to optimize your program...

For more details about qx::cache : http://www.qxorm.com/qxorm_en/faq.html#faq_220
For more details about triggers : http://www.qxorm.com/qxorm_en/faq.html#faq_130

Re: Can I use an id instead of reference object?

PostPosted: Fri Feb 10, 2012 4:22 pm
by magicu
QxOrm admin wrote:If you are sure that your authorPtr already exists into database, I think that you can set only the ID => It would work...



It won't work, I test some code like this:

Code: Select all
AuthorPtr authorPtr (new Author);
authorPtr ->id = 1; // The id 1 is exist in author

BlogPtr blogPtr(new Blog);

blogPtr->authorPtrX = authorPtr;
blogPtr->blog_text = "";
blogPtr->....

qx::dao::insert_with_all_relationship(blogPtr);  // "qx::dao::insert(blogPtr);" is also invalid




No error occored, but I found nothing in DB :cry:

Re: Can I use an id instead of reference object?

PostPosted: Fri Feb 10, 2012 4:54 pm
by QxOrm admin
What is the SQL generated by QxOrm library in your degugger window please ?