I need to delete a record using Zend_Db_Table referencing the rence table. In SQL the query would look like this:
DELETE t1 FROM t1 LEFT JOIN t2 ON t1.id=t2.id WHERE t2.id IS NULL;
Is there a way to do this more elegant than the code below?
$table = new Application_Model_DbTable_T1();
$sql = 'DELETE t1 FROM t1 LEFT JOIN t2 ON t1.id=t2.id WHERE t2.id IS NULL;';
$table->getAdapter()->query($sql);
I found a similar topic and it looks like I should use $table->getAdapter()->query($sql);
but I hope for better.
No, the way you discribe it is the right way to do it.
I assume that Application_Model_DbTable_T1
extends Zend_Db_Table_Abstract
or its subclass. The thing about Zend_Db_Table_Abstract
is that it is meant to only work with a single table. And you are trying to access more than one table in this query.
So the way to do this is the same way you are doing. Retrieve the Adapter, which does not depend on the table, and thus can interact with more than one table at the time.
TL;DR: This is the right way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With