Skip to content Skip to sidebar Skip to footer

What Is The Syntax For A Multi-table Delete On A Mysql Database Using Doctrine?

Using Doctrine, I am trying to delete records in a single table based on data gathered from multiple tables. 'companies_groups' is an association table linking 'companies' to 'grou

Solution 1:

Solved it. Rather than try to build the join myself I used a subquery and didn't try to force Doctrine to construct the SQL in a specific way.

For anyone else that ever needs to do something like this, here is what ended up working:

$query = Doctrine_Query::create()
  ->delete('Company_group')
  ->where( "companyID = ?", array( $companyID ) )
  ->addWhere( "groupID IN (SELECT g.id FROM Group g WHERE g.groupType = 'public')" );

Cheers.

Post a Comment for "What Is The Syntax For A Multi-table Delete On A Mysql Database Using Doctrine?"