📜 ⬆️ ⬇️

Select loses ON when JOIN'e

Faced a problem in ZF.
There are two related tables. Both inherit from Zend_Db_Table_Abstract. We form a query to the database:

$select = $this->select();
$select->where('Catalog.trashed = ?', 1)
->where('C.trashed = ?', 0)
->join(array('C' => 'Categories'), 'C.id = Catalog.categoryid', array())
->order($sort);


We look at the query to the database:
SELECT `Catalog`.* FROM `Categories` AS `C` INNER JOIN `Catalog` WHERE (Catalog.trashed = 1) AND (C.trashed = 0) ORDER BY `sort` ASC

ON in the JOIN is lost.


And here is the solution:
')
$select = $this->select();
$select->assemble();
$select->where('Catalog.trashed = ?', 1)
->where('C.trashed = ?', 0)
->join(array('C' => 'Categories'), 'C.id = Catalog.categoryid', array())
->order($sort);


We get:
SELECT `Catalog`.* FROM `Catalog` INNER JOIN `Categories` AS `C` ON C.id = Catalog.categoryid WHERE (Catalog.trashed = 1) AND (C.trashed = 0) ORDER BY `sort` ASC

These are the pies. Can someone help ...

Crosspost from blog

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


All Articles