delete_by_id_with_relations

Forum for posting problems using QxOrm library

delete_by_id_with_relations

Postby BlackSoul » Tue Dec 17, 2013 6:30 am

Hi.
I have two classes with relation n-1 like this:

Code: Select all
class A
{
public:
     long id;
     QSharedPointer< B > b;
};

class B
{
public:
    long id;
    QList< QSharedPointer< A > > a_list;
};
typedef QSharedPointer< B > BPtr;


can i delete record from both tables at once( like delete_by_id_with_all_relations ) or i must do something like following:
Code: Select all
BPtr b( new B );
b->id = < id_to_delete >
qx::orm::fetch_by_id( b );
qx::orm::delete_by_id( a_list )
qx::orm::delete_by_id( b );


Thanks.
Last edited by BlackSoul on Tue Dec 17, 2013 9:21 am, edited 1 time in total.
BlackSoul
 
Posts: 6
Joined: Tue Dec 17, 2013 6:14 am

Re: delete_by_id_with_with_relations

Postby qxorm » Tue Dec 17, 2013 8:23 am

Hi,

There is no qx:: dao:: delete_by_id_with_relation() function.
You can do that in multiple ways :
1- define in your SGBD (your schema definition) : ON DELETE CASCADE ;
2- or use QxOrm triggers (onBeforeDelete or onAfterDelete) : http://www.qxorm.com/qxorm_en/faq.html#faq_130 ;
3- or do it manually as you said in your topic.
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am


Return to QxOrm - Help

Who is online

Users browsing this forum: No registered users and 6 guests

cron