Delete row from Zend_Db_Table with JOIN

I need to delete a record using Zend_Db_Table referencing the rence table. In SQL, the query will 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 make 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 the best.

+4
source share
1 answer

No, the way you describe it is the right way to do it.

I assume Application_Model_DbTable_T1 extends Zend_Db_Table_Abstract or its subclass. The thing about Zend_Db_Table_Abstract is that it is designed to work with only one table. And you are trying to access more than one table in this query.

So, the way to do this is the same as you. Remove an adapter that is table independent, and thus can interact with more than one table at a time.

TL DR: This is the right way.

+1
source

Source: https://habr.com/ru/post/1383831/


All Articles