views:

215

answers:

1

I want to retrieve multiples values from a field. the code I am using this this

$conditions = array('Tag.name'=>$compare);//$compare = array('value1', 'value2',..);
$values = $this->find('all', array('conditions' => $conditions));

But It keeps coming out like this

    SELECT `Tag`.`id`, `Tag`.`name`, `Tag`.`count` FROM `tags` AS `Tag` WHERE `Tag`.`name` IN ('tag2', ' tag1', ' one tag')

Problem is it only retrieves the first value given. instead of all the values . How do I get it to select all the values in the array.

+2  A: 

What version of Cake are you using?

But the main thing is that your conditions needs to be in a fields array.

find('all', array(
'conditions' => array('name' => 'Thomas Anderson'),
'fields' => array('name', 'email'),
'order' => 'field3 DESC',
'recursive' => 2,
'group' => 'type'
));

Ref, Model::find() API Docs

The reason your query is not working is that you need to move it into that pattern..

So your query would be,

$compare = array('value1', 'value2');
$values = $this->Model->find('all', array('fields' => $compare));

Not sure on your example if you meant to omit it, but always best to include the model you are running the find against :)

DavidYell