Can I use an id instead of reference object?

Forum for posting problems using QxOrm library

Can I use an id instead of reference object?

Postby magicu » Fri Feb 10, 2012 9:51 am

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?
magicu
 
Posts: 54
Joined: Fri Jan 20, 2012 9:51 am

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

Postby QxOrm admin » Fri Feb 10, 2012 12:03 pm

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
QxOrm admin
 

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

Postby magicu » Fri Feb 10, 2012 4:22 pm

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:
magicu
 
Posts: 54
Joined: Fri Jan 20, 2012 9:51 am

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

Postby QxOrm admin » Fri Feb 10, 2012 4:54 pm

What is the SQL generated by QxOrm library in your degugger window please ?
QxOrm admin
 


Return to QxOrm - Help

Who is online

Users browsing this forum: No registered users and 10 guests

cron