dqhdz04240 2010-10-23 18:53 采纳率: 0%
浏览 72
已采纳

Zend_Db_Select:使用JOIN的

I have this query:

SELECT
    groups.name
    categories.name,
    categories.label
FROM
    groups
JOIN
    categories
ON
    (categories.group1 = groups.id
OR
    categories.group2 = groups.id)
AND
    groups.label = :section
AND
    categories.active = 1

Now, this is my JOIN using Zend_Db_Select but it gives me array error

$select->from($dao, array('groups.name', 'categories.name', 'categories.label'))
       ->join(array('categories', 'categories.group1 = groups.id OR categories.group2 = groups.id'))
       ->where('groups.label = ?', $group)
       ->where('categories.active = 1');

My error:

Exception information:

Message: Select query cannot join with another table

Does anyone know what I did wrong?

UPDATE / SOLUTION:

I've found the solution thanx to Eran. I just post the solution here in case anyone else is stuck on a problem like this one. The solution is:

$db = Zend_Registry::get('db');
$dao = new Default_Model_Db_CategoryDao('db');
$select = $dao->select();

$select->setIntegrityCheck(false)
       ->from(array('c' => 'categories'), array('name', 'label'))
       ->join(array('g' => 'groups'), 'c.group1 = g.id OR c.group2 = g.id', 'g.label')
       ->where('g.label = ?', $group)
       ->where('c.active = 1');

return $dao->fetchAll($select);

展开全部

  • 写回答

1条回答 默认 最新

  • dsh12544 2010-10-23 18:58
    关注

    You are using a Zend_Db_Table_Select object. Those by default have integrity check enabled and cannot select data that is outside of their table.

    You can turn it off by adding -> setIntegrityCheck(false) to the select object before querying with it.

    You can read more about it in the manual under Select API -> Advanced usage

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部