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....
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();
id_category
and not last_sync
=> Only ONE row last_sync
and not id_category
=> Multiples rows last_sync
and id_category
=> Only ONE row Why? I suppose it's because I use bsn_id_category
in select
but I don't understand ....
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"
:
$this->select
->setIntegrityCheck(false)
->joinLeft('business', 'news_id = bsn_id', array());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.