DQL delete from multiple tables (doctrine)
Posted
by singer
on Stack Overflow
See other posts from Stack Overflow
or by singer
Published on 2010-06-11T12:03:56Z
Indexed on
2010/06/11
15:03 UTC
Read the original article
Hit count: 366
Need to perform DQL delete from multple related tables. In SQL it is something like this:
DELETE r1,r2
FROM ComRealty_objects r1, com_realty_objects_phones r2
WHERE r1.id IN (10,20) AND r2.id_object IN (10,20)
I need to perform this statement using DQL, but I'm stuck on this :(
<?php
$dql = Doctrine_Query::create()
->delete('phones, comrealtyobjects')
->from('ComRealtyObjects comrealtyobjects')
->from('ComRealtyObjectsPhones phones')
->whereIn("comrealtyobjects.id", $ids)
->whereIn("phones.id_object", $ids);
echo($dql->getSqlQuery());
?>
But DQL parser gives me this result:
DELETE FROM `com_realty_objects_phones`, `ComRealty_objects`
WHERE (`id` IN (?) AND `id_object` IN (?))
Searching google and stack overflow I found this(useful) topic:
http://stackoverflow.com/questions/2247905/what-is-the-syntax-for-a-multi-table-delete-on-a-mysql-database-using-doctrine
But this is not exactly my case - there was delete from single table.
If there is a way to override dql parser behaviour? Or maybe some other way to delete records from multiple tables using doctrine.
Note: If you are using doctrine behaviours(Doctrine_Record_Generator) you need first to initialize those tables using Doctrine_Core::initializeModels() to perform DQL operations on them.
© Stack Overflow or respective owner