2011-12-03 14 views
1

我有一個問題,我的課(由Zend_Db_Table_Abstract擴展),它返回,每次只有一排有一個連接,並選擇....當我用我的選擇Zend_Db_Table_Abstract和加入,使用fetchall還給我一個行

我在互聯網上搜索,但我沒有發現這個「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_syncid_category =>只有一行

爲什麼?我想這是因爲我在select中使用bsn_id_category,但我不明白....

我該如何解決這個問題? =)

Calumah

回答

0

大廈的最後答案,試試這個:

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

嘗試完整性檢查設置爲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()); 
+0

帶或不帶setIntegrityCheck設爲假,我再次得到一行....:/ – Calumah

相關問題