我有一个带有两个扩展 Zend_Db_Table_Abstract 模型的模块:
class Departments_Model_Subpages extends Zend_Db_Table_Abstract
{
protected $_name = 'bktg_departments_subpages';
protected $_primary = 'id';
}
class Departments_Model_Departments extends Zend_Db_Table_Abstract
{
protected $_name = 'bktg_departments';
protected $_primary = 'id';
}
通读文档,我想做的是这样的(显然,错误):
$depTable = new Departments_Model_Departments();
$subTable = new Departments_Model_Subpages();
$depQuery = $depTable->select()->setIntegrityCheck(false)
->from($depTable, array('id', 'title'))
->join($subTable, array('COUNT(id) as `count`'))
->where('bktg_departments.id = bktg_departments_subpages.parent_id');
我错过了什么?我只是无法理解 Zend 连接,我想我最终会直接写 sql。
谢谢你看。
编辑
这是我现在正在使用的内容:
$depQuery = $depTable->select()->setIntegrityCheck(false)
->from($depTable, array('id', 'title'))
->joinLeft($subTable, 'bktg_departments.id = bktg_departments_subpages.parent_id', array('COUNT(id) as count'))
->order('id DESC')
->group('id');
对我有用的sql:
SELECT bktg_departments.id, bktg_departments.title, count(bktg_departments_subpages.id) FROM bktg_departments left join bktg_departments_subpages on bktg_departments.id = bktg_departments_subpages.parent_id group by bktg_departments.id
我在 Zend 中复制它时遇到了问题。