2011-11-30 51 views
0

我試圖做一個查找語句來獲取內容相應的CakePHP中可容納的錯誤

users(id, name, city_id) 
visitors(id, user_id, visitor_id) // visitor_id also refers to users table 
cities(id, name) 

PHP

$visitor_data = $this->User->Visitor->find('all', array(
      'conditions' => array('user_id' => 1), 
      'limit' => 10, 
      'order' => array('timestamp DESC'), 
      'contain' => array('VisitorDetails' => array(
                'fields' => array('id', 'first_name', 'last_name', 'username', 'city_id'), 
                'contain' => array('City')) 
                ) 
      )); 

我得到一個錯誤:

SQL Error: 1054: Unknown column 'VisitorDetails.contain' in 'field list'

我想獲得Visitor Det苦惱的城市信息

回答

2

VisitorDetails應爲單數:

'contain' => array('VisitorDetail' .....

2
<?php $visitor_data = $this->User->Visitor->find('all', array(
      'conditions' => array(
       'user_id' => 1 
      ), 
      'limit' => 10, 
      'order' => array(
       'timestamp DESC' 
      ), 
      'contain' => array(
       'VisitorDetail' => array(
        'fields' => array(
         'id', 
         'first_name', 
         'last_name', 
         'username', 
         'city_id' 
        ), 
        'contain' => array(
         'City' 
        ) 
       ) 
      ) 
      )); 
?> 
+0

這是最好保持一個有組織的結構代碼,以便其他程序員可以輕鬆/快速地解釋它。 – jwg2s