I'm trying to retrieve the latest images uploaded to my site but not when they're in a private gallery, event or if the user is deleted. I need to do these checks on a 0 or a null as well.
I've looked around and found a fair few ways of doing multiple and's and multiple or's but not together. It seems to look correct but doesn't work at all.
$conditions = array(
'AND' => array(
array(
'OR' => array(
'Event.private' => null,
'Event.private' => 0
)
),
array(
'OR' => array(
'Gallery.private' => null,
'Gallery.private' => 0
)
),
array(
'OR' => array(
'User.deleted' => null,
'User.deleted' => 0
)
)
)
);
$images = $this->Image->find('all',array(
'order'=>array('Image.id'=>'desc'),
'limit'=>$limit,
'group'=>'Image.id',
'offset'=>$offset,
'conditions'=>$conditions)
);
The OR statements should probably be also in an array.
Try following conditions:
$conditions = array(
'AND' => array(
array(
'OR' => array(
array('Event.private' => null),
array('Event.private' => 0)
)
),
array(
'OR' => array(
array('Gallery.private' => null),
array('Gallery.private' => 0)
)
),
array(
'OR' => array(
array('User.deleted' => null),
array('User.deleted' => 0)
)
)
)
);