我有一个问题与我的类(扩展由Zend_Db_Table_Abstract),它返回只有一行每次与一个连接和选择....
我在网上搜索,但我没有找到这个"bug"!
class Api_Model_News extends Zend_Db_Table_Abstract
{
protected $_name = 'news';
protected $_primary = 'news_id';
protected $select;
public function init()
{
$this->select = $this->select();
}
public function setTimestamp($timestamp)
{
$this->select
->where('news_timestamp >= ?', $timestamp);
return $this;
}
public function setCategory($id_category)
{
$this->select
->where('bsn_id_category = ?', $id_category);
return $this;
}
public function getNews()
{
$this->select
->from('news')
->joinLeft('business', 'news_id = bsn_id', array());
$data = $this->fetchAll($this->select);
return $data->toArray();
}
}
在另一个函数中:
$news = new Api_Model_News();
if ($id_category != NULL)
$news->setCategory($id_category);
if ($last_sync != NULL)
$news->setTimestamp($last_sync);
return $news->getNews();
- 当我设置
id_category
而不是last_sync
=>仅一行 - 当我设置
last_sync
而不是id_category
=>多行 - 当我设置
last_sync
和id_category
=>只有一行
为什么?我想这是因为我在select
中使用bsn_id_category
,但我不明白....
在上一个答案的基础上,试试这个:
$this->select(Zend_Db_Table::SELECT_WITH_FROM_PART)
->setIntegrityCheck(false)
->joinLeft('business', 'news_id = bsn_id', array());
尝试将完整性检查设置为false,如"Setting this flag to false skips the checks for table joins, allowing 'hybrid' table rows to be created"
:
$this->select
->setIntegrityCheck(false)
->joinLeft('business', 'news_id = bsn_id', array());