复杂的查找语句,不知道如何为一个条件写多个值

时间:2012-03-08 21:28:49

标签: cakephp-2.0 cakephp-appmodel

我正在尝试为我的Unit模型构建一个分页查找调用。我需要条件是它寻找unit.type of condo和rentalco,house和rentalco,但不是rentalco和hotel。另外,我的代码措辞方式,蛋糕只返回rentalco的单位类型。

public function view($type=null) {
$this->set('title', 'All '.$type.' in and near Gulf Shores');
$this->set('featured', $this->Unit->getFeatured());
$this->paginate['Unit']=array(
        'limit'=>9,
        'order' => 'RAND()',
        'contain'=>array(
                'User'=>array('id'),
                'Location',
                'Complex',
                'Image'
                    ),
        'conditions'=>array(
                'Unit.type'=>array($type, 'rentalco'),
                'Unit.active'=>1)   
    );
   $data = $this->paginate('Unit');
   $this->set('allaccommodations', $data);
$this->set('type', $type);
}

更新我弄清楚为什么我的查找声明无法正常工作(只是将单词condos而不是condo传递到我的浏览器栏中... derp derp);然而,我仍然想知道我怎么能告诉蛋糕不允许找到类型酒店和rentalco。

1 个答案:

答案 0 :(得分:0)

您正在寻找NOT。它会是这样的:

'conditions' => array(
    'NOT' => array('Unit.type' => array('hotel', 'rentalco')),
),

更具体地说,我需要查看您的模型架构。