cakephp可容纳的条件问题

时间:2011-07-27 10:56:14

标签: mysql 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' 

1 个答案:

答案 0 :(得分: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的{​​{1}}数组之前。这是一个黑暗的镜头,但我猜这可能会设置您的contain()首先被查询,为您提供UsersLocation查询的必要信息。