繁体   English   中英

当我将我的Zend_Db_Table_Abstract与select和join一起使用时,fetchAll返回我一行

[英]When i use my Zend_Db_Table_Abstract with select and join, fetchAll return me one row

我的班级遇到问题(由Zend_Db_Table_Abstract扩展),每次通过联接和选择仅返回一行。

我在互联网上进行搜索,但没有发现此“错误”!

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_syncid_category =>仅一行时

为什么? 我想这是因为我在select使用bsn_id_category ,但我不明白...。

在最后一个答案的基础上,尝试以下操作:

 $this->select(Zend_Db_Table::SELECT_WITH_FROM_PART)
       ->setIntegrityCheck(false)
       ->joinLeft('business', 'news_id = bsn_id', array());

尝试将完整性检查"Setting this flag to false skips the checks for table joins, allowing 'hybrid' table rows to be created"为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());

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM