Page 1 of 1

Many2Many Relationship Lifecycle Management

PostPosted: Mon Nov 14, 2016 11:00 pm
by Kasuax
How do you typically manage Many2Many relationships?

Without a lot of build up I'm realizing that I'm going to have to do a lot of manual prep work to make these guys work. Particularly with delete it would appear. Will I have to implement custom onBeforeDelete operations for these objects? What would those functions look like? Below is where I'm currently at and admittedly struggling through this concept.

Code: Select all
void Project::onBeforeDelete(qx::dao::detail::IxDao_Helper * dao)
{   
    qx::QxSqlQuery query("WHERE t_qxee_User_Project.project_id = :key");
    query.bind(":key", m_Project_ID.toString());
   
    if (!qxTryCatch(qx::dao::execute_query(query, dao->database())))
    {
        qx::QxInvalidValueX msg;
        msg.insert("Unable to detach project from user accounts!");

        dao->addInvalidValues(msg);
    }
}

Re: Many2Many Relationship Lifecycle Management

PostPosted: Tue Nov 15, 2016 7:57 am
by qxorm
Will I have to implement custom onBeforeDelete operations for these objects?

No.

What is your problem exactly ? I don't understand.

What you could do if you prefer is to split your n-n relationship to two n-1 and 1-n relationships.
This is what QxEntityEditor do for example during an import process : QxEntityEditor never creates automatically a n-n relationship.