Does QxOrm support cascading delete?

Forum for posting problems using QxOrm library

Does QxOrm support cascading delete?

Postby Guest » Thu Feb 09, 2012 4:15 am

If I must delete twice?
Guest
 

Re: Does QxOrm support cascading delete?

Postby QxOrm admin » Thu Feb 09, 2012 8:16 am

Hi,

There is another topic on this forum with the same question, goto here for more details :
viewtopic.php?f=2&t=23

For cascading delete, I see 2 solutions :
- define it into your database during table creation (SQL schema) => adding a constraint on foreign key ;
- or use the notion of trigger to delete manually into your C++ code.

For QxOrm triggers, you can find an example here :
http://www.qxorm.com/qxorm_en/faq.html#faq_130

And your code could look like :
Code: Select all
void BaseClassTrigger::onAfterDelete(qx::dao::detail::IxDao_Helper * dao)
{
   // If an error has been generated before this process
   if (dao->error().isValid()) { return; }

   // Retrieve current connexion to database
   QSqlDatabase connexion = dao->database();

   // Delete my object manually with the same connexion
   QSqlError error = qx::dao::delete_by_id(my_object, & connexion);

   // If an error occured : transfert error to dao parameter
   if (error.isValid()) { dao->updateError(error); }
}
QxOrm admin
 


Return to QxOrm - Help

Who is online

Users browsing this forum: No registered users and 6 guests