Change find() type of contained model or array transformation
Posted
by Ramon Marco Navarro
on Stack Overflow
See other posts from Stack Overflow
or by Ramon Marco Navarro
Published on 2010-05-15T19:14:07Z
Indexed on
2010/05/15
19:14 UTC
Read the original article
Hit count: 161
I have the following model associations:
Response->Survey
Response->Question
Response->Choice
Survey->Question
Question->Choice
I want to create a form where I could answer all the questions for one survey. So I used the following to return the needed data:
$questions = $this->Response->Question->find('all', array(
'conditions' => array('survey_id' => $id),
'contain' => array('Choice')
)
);
Sample output for debug($questions)
.
Questions
Is there a
contain()
option so that an associated model returns in thefind('list')
format so that I could use:foreach($question as $questions) { $this->Form->select('field_name', $question['Choice']); }
If no option is available, how could I do this using PHP's builting array methods?
PS: The foreach block won't turn into a code block. If someone could edit and fix it, please do so and delete this line. Thank you.
© Stack Overflow or respective owner