I have trouble finding items that belong to two or more categories in cakephp 2
.
In my Controller I have the following:
$kategories = array(1,2);
$options['conditions'] = array('Categorie.id' => $kategories);
$items = $this->Item->find('all',$options);
The query above shows all Items that have either associated category-id 1 or 2.
How can I search for all items, that belong to category.id 1
AND 2
(not OR).
I tried using the 'AND' array with no luck:
$options['conditions'] = array('AND' => array('Categorie.id' => $kategories));
Any ideas?
Thanks in advance!!
I looked a little further on this and found the solution:
To find all items, that belong to category.id 1 AND 2 (not OR) I just had to add a 'group' parameter to my find like this:
The complete query (working):