I am using symfony+doctrine, and I want to perform a delete query with a join. See below for my code I am currently using that works fine.
$sql = 'DELETE a
FROM a
INNER JOIN b ON a.b_id = b.id
WHERE b.c_id = :c_id';
$pdo = Doctrine_Manager::getInstance()->getCurrentConnection()->getDbh();
$stmt = $pdo->prepare($sql);
$params = array('c_id' => $c_id);
$stmt->execu开发者_运维问答te($params);
Anyone know how I can do this using:
Doctrine_Core::getTable('a')
Or
Doctrine_Query::create()->delete()->from('a')
I have had no luck with either.
I just don't really want to use raw SQL in my app.
Something like this should do it
Doctrine_Query::create()
->delete('a a')
->innerJoin('a.b b')
->where('b.c_id = ?', $c_id)
->execute()
精彩评论