简体   繁体   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

I have a problem with my class (extend by Zend_Db_Table_Abstract), it returns with only one row each time with a join and select.... 我的班级遇到问题(由Zend_Db_Table_Abstract扩展),每次通过联接和选择仅返回一行。

I searched on the internet but I found nothing on this "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();
}

}

In another function: 在另一个功能中:

$news = new Api_Model_News();                    

if ($id_category != NULL)
  $news->setCategory($id_category);

if ($last_sync != NULL)
  $news->setTimestamp($last_sync);

return $news->getNews();
  • When I set id_category and not last_sync => Only ONE row 当我设置id_category而不是last_sync =>时只有一行
  • When I set last_sync and not id_category => Multiples rows 当我设置last_sync而不是id_category =>多行时
  • When I set last_sync and id_category => Only ONE row 当我设置last_syncid_category =>仅一行时

Why? 为什么? I suppose it's because I use bsn_id_category in select but I don't understand .... 我想这是因为我在select使用bsn_id_category ,但我不明白...。

Building on the last answer, try this: 在最后一个答案的基础上,尝试以下操作:

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

Try to set the integrity check to false as "Setting this flag to false skips the checks for table joins, allowing 'hybrid' table rows to be created" : 尝试将完整性检查"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