Reputation: 27
I'm trying to do this:
$customers = $this->Customer->find('list', array('conditions' => //some code));
$conditions = array('Event.customer_id' => $customers //here's the problem);
$this->Event->find('all', ('conditions' => $conditions));
the $customers find returns:
array(
[id1] => "Cust name 1",
[id2] => "Cust name 2",
...
[idn] => "Cust name n")
while I need that in the $conditions the $customers array should be a list of customer id's to find what I need, instead it uses the display value (es. "Cust name n") so the find returns an empty $events variable.
How is possible to use the array index instead of the array value in a find condition filter?
I know this could be easy but I'm really stuck here.
thanks.
Upvotes: 0
Views: 1299
Reputation: 1839
You only need to change your code like this:
$customers = $this->Customer->find('list', array('conditions' => //filter));
$conditions = array('Event.customer_id' => array_keys( $customers) );
$this->Event->find('all', ('conditions' => $conditions));
Notice that you pass array_keys( $customers )
instead of simply the array. That will extract the IDs you need in a format that CakePHP can use.
Upvotes: 1