2012-07-29 92 views
1

我有一個名爲'Interestslogs'的表,模型的名稱是Interestlog。Cakephp:find()錯誤:SQLSTATE [42S22]:未找到列:1054'字段列表'中的未知列'Interestslogs.interest_id'

我需要根據CakePHP中該表的id獲取client_id。

$client_id = $this->Interestslog->find('first',array(
     'conditions' => array('Interestslogs.id' => $id), 
     'fields' => array('Interestslogs.client_id'), 
     ) 
    ); 

但是我得到數據庫錯誤:

Database Error 

錯誤:SQLSTATE [42S22]:列未找到:1054未知列 'Interestslogs.interest_id' 在 '字段列表'

SQL查詢:SELECT Interestslogsinterest_idefainterestslogs AS Interestslog LEFT JOIN efainterests AS Interest ON(Interestsloginterest_id = Interestid)LEFT JOIN efaclients AS Client ON(Interestslogclient_id = Clientid)WHERE Interestslogsid = 1 LIMIT 1

+1

**檢查您的「興趣日誌」表中是否包含「interest_id」字段** – thecodeparadox 2012-07-29 13:54:23

回答

0

你可以試試:(如果你的關係都沒事)

$this->Interestslog->recursive = -1; 
$client_id = $this->Interestslog->find('first',array(
    'conditions' => array('Interestslogs.id' => $id), 
    'fields' => array('Interestslogs.client_id'), 
    ) 
); 
0

檢查是否有interest_id列在您的Interestlogs表。

或者嘗試

$variable_temp = $this->Interestslog->findById($id); 
//debug($variable_temp); 
$client_id = $variable['client_id']; 
0
$client_id = $this->Interestslog->find('first',array(
     'conditions' => array('Interestslog.id' => $id), 
     'fields' => array('Interestslog.client_id'), 
     ) 
    ); 

你應該寫在表名的條件/場陣中沒有最後的「s」,因爲它是由CakePHP的自動添加。

1

刪除複數的 「S」 形Interestslogs

$client_id = $this->Interestslog->find('first',array(
    'conditions' => array('Interestslog.id' => $id), 
    'fields' => array('Interestslog.client_id'), 
    ) 
); 

,並檢查你的模型。如果每件事情(客戶和利益博客)都正確關聯,你就不應該得到任何錯誤。

相關問題