Cakephp 2.0 复杂的find语句,don';我不知道如何为一个条件写多个值
我正在尝试为我的单元模型构建一个分页的find调用。我需要的条件是,它寻找的单位。类型的公寓和rentalco,房子和rentalco,但不是rentalco和酒店。此外,按照我的代码措辞,cake只返回rentalco的单元类型Cakephp 2.0 复杂的find语句,don';我不知道如何为一个条件写多个值,cakephp-2.0,cakephp-model,Cakephp 2.0,Cakephp Model,我正在尝试为我的单元模型构建一个分页的find调用。我需要的条件是,它寻找的单位。类型的公寓和rentalco,房子和rentalco,但不是rentalco和酒店。此外,按照我的代码措辞,cake只返回rentalco的单元类型 public function view($type=null) { $this->set('title', 'All '.$type.' in and near Gulf Shores'); $this->set('featured', $this-&g
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);
}
更新我找到了我的find语句不起作用的原因(只是把condos这个词而不是condo传递到了我的浏览器栏……derp derp);然而,我仍然很想知道我如何告诉cake不要让type hotel和rentalco都找到它 您正在寻找的不是。可能是这样的:
'conditions' => array(
'NOT' => array('Unit.type' => array('hotel', 'rentalco')),
),
更具体地说,我需要查看您的模型模式。这很有效。我在手册中看到了NOT语句,但我没有意识到它将作为一个“不将这两个放在一起”选项工作。非常感谢。