Page 1 of 1

delete_by_id_with_relations

PostPosted: Tue Dec 17, 2013 6:30 am
by BlackSoul
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.

Re: delete_by_id_with_with_relations

PostPosted: Tue Dec 17, 2013 8:23 am
by qxorm
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.