2011-07-27 54 views
2

假設下表:cakephp的中可容納條件問題

  • businesses_locations(location_state_id)
  • users_locations(location_state_id)
  • businesses_reviews(USER_ID,business_id)。

BusinessesReview上的'find'調用應該如何選擇只有那些用戶在業務狀態中出現DIFFERS的條目?

$this->BusinessesReview->contain(array('BusinessesProfile'=>array('BusinessesLocation'),'User'=>array('UsersLocation'))); 
$results = $this->BusinessesReview->find('all', array('conditions'=>array('BusinessesLocation.location_state_id <> UsersLocation.location_state_id'))); 

給出了錯誤:

MySQL Error: 1054: Unknown column 'BusinessesLocation.location_state_id' 

回答

0

您將需要把這個在您的contain通話

$this->BusinessesReview->contain(
    array(
     'BusinessesProfile' => array(
      'BusinessesLocation' => array(
       'conditions' => array(
        'BusinessesLocation.location_state_id <> UsersLocation.location_state_id' 
       ) 
      ) 
     ), 
     ... // rest of the array goes here 
    ) 
); 

答評論:嘗試把User陣列中的BusinessesProfile陣列之前您的contain()。這是在黑暗中拍攝的,但我猜這可能會設置您的UsersLocation首先被查詢,爲您提供BusinessesProfile查詢的必要信息。

+0

它似乎更近一步,現在我得到:未知的列'UsersLocation.location_state_id'在'where子句'..任何想法? :) – raver