2010-09-20 30 views
1

連接表爲什麼會出現這樣的:錯誤而與Zend_Db的

An error occurred 

Application error 

Exception information: 

Message: Select query cannot join with another table 

,同時試圖連接兩個表?

我這行代碼,我的模型延伸Zend_Db_Table_Abstract

public function getProjects() { 
    $select = $this->select() 
      ->from(array('sub' => $this)) 
      ->join(array('main' => 'main_projects'), 'main.mai_id = sub.mai_id'); 
    return $this->fetchAll($select); 
} 

內,我用這個在我的控制器:$this->view->entries = $this->sub_projects->getProjects();

憑啥我得到這個錯誤?我只想做一個簡單的加入

SELECT sub.*, main.mai_title FROM sub_projects AS sub INNER JOIN main_projects AS main ON sub.mai_id = projects.mai_id; 
enter code here 

回答

1

我覺得這裏是您的解決方案,並解釋:http://www.mail-archive.com/[email protected]/msg24553.html 另一種解決方案在這裏:Translating a query to use Zend_Db_Select

+0

然後我得到:'SQLSTATE [42S02]:基表或視圖未找到:1146表'ccgss.object'不存在' – 2010-09-20 18:47:27

+0

其實我也必須更改'$ this'作爲表名 – 2010-09-20 18:58:17

+0

儘管這個答案在理論上可以回答這個問題,[更好](http:// meta.stackexchange.com/q/8259)在這裏包含答案的基本部分,並提供供參考的鏈接。 – hichris123 2014-02-05 19:29:53