0

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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.