开发者

cakephp containable condition problem

assume the following tables:

  • businesses_locations (location_state_id)
  • users_locations(location_state_id)
  • businesses_reviews(user_id, business_id).

How should a 'find' call on BusinessesReview look like in order to select only those entries where the user state DIFFERS from the busines开发者_开发技巧s state?

$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')));

gives error:

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


You would need to put this in your contain call

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

Answer to comment: Try putting the User array before the BusinessesProfile array in your contain(). This is a shot in the dark but I'm guessing this might set up your UsersLocation to be queried first, giving you the necessary information for the BusinessesProfile query.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜