"IS NULL";在Zend_Db_Table中选择不起作用 [英] "IS NULL" in Zend_Db_Table select not working

查看:75
本文介绍了"IS NULL";在Zend_Db_Table中选择不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用DbTable/model/mapper结构对Zend中的2个表进行联接. 如果在我的映射器中这样做:

I'm trying to do a join on 2 tables in Zend, using the DbTable / model / mapper structure. If, in my mapper, I do this:

$select = $this->getDbTable()->select(Zend_Db_Table::SELECT_WITH_FROM_PART)
        ->setIntegrityCheck(false)
        ->join('images', 'images.oldFilename =
                                               availablePictures.filename')
               ->where('images.ref IS NOT NULL');
$resultSet = $this->getDbTable()->fetchAll( $select );

它的工作原理很吸引人,但是如果我使用IS NULL而不是NOT NULL尝试相同的操作,那么在应该得到几行结果集的地方我什么也没得到,就像我直接在MySQL中使用

it works like a charm, but if I try the same thing with IS NULL instead of NOT NULL, I get nothing where I should get a result set of several rows, just like when I try it directly in MySQL with

SELECT *
FROM (
`availablePictures` AS a
LEFT JOIN `images` AS i ON a.filename = i.oldFilename
)
WHERE i.`ref` IS NULL

我给人的印象是Zend不喜欢我的IS NULL或我做错了什么?

I get the impression Zend doesn't like my IS NULL or am I doing something wrong?

推荐答案

该解决方案可以在Machine对我的原始帖子的评论中找到. 按照他的建议,我注意到Zend在使用错误的select方法时创建了一个内部联接,所以:

The solution was to be found in Machine's comment on my original post. Doing what he suggested I noticed that Zend created an inner join as I was using the wrong select method, so:

$select = $this->getDbTable()->select(Zend_Db_Table::SELECT_WITH_FROM_PART)
        ->setIntegrityCheck(false)
        ->joinLeft('images', 'images.oldFilename =
                                               availablePictures.filename')
               ->where('images.ref IS NOT NULL');
$resultSet = $this->getDbTable()->fetchAll( $select );

应该是这样.

这篇关于"IS NULL";在Zend_Db_Table中选择不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆