hey I have problems with saving 3 models together.
if I just have to models (Quiz and QuizQuestion) I can do it whit
saveAll if my array looks like the below.
but then I can't save the QuizAnswer (and get a question_id on it) so
I tryed to set up me array like the bottom but now it only saves the
[Quiz]
Array
(
[Quiz] => Array
(
[title] => dsfdsfd
)
[QuizQuestion] => Array
(
[1] => Array
(
[question] => Test
)
)
[QuestionAnswer] => Array
(
[1] => Array
(
[answer] => 1
)
)
)
/* as it looks like now */
// array output
Array
(
[Quiz] => Array
(
[title] =>
[QuizQuestion] => Array
(
[1] => Array
(
[question] => 32432
[QuestionAnswer] => Array
(
[1] => Array
(
[answer] => 234
)
)
)
[2] => Array
(
[question] => 32432
[QuestionAnswer] => Array
(
[1] => Array
(
[answer] => 324
)
)
)
)
)
)
// quiz model
<?php
class Quiz extends AppModel {
var $name = 'Quiz';
var $actsAs = array('Searchable.Searchable');
public $hasMany = array(
'QuizQuestion' => array(
'className' => 'QuizQuestion',
'foreignKey' => 'quiz_id'
)
);
}
// quiz_question model
<?php
class QuizQuestion extends AppModel {
var $name = 'QuizQuestion';
var $useTable = 'quiz_questions';
var $belongsTo = array(
'Quiz' => array(
'className' => 'Quiz',
'foreignKey' => 'quiz_id'
)
);
public $hasMany = array(
'QuizAnswer' => array(
'className' => 'QuizAnswer',
'foreignKey' => 'question_id'
)
);
}
// quiz_answer model
<?php
class QuizAnswer extends AppModel {
var $name = 'QuizAnswer';
var $useTable = 'quiz_answers';
var $belongsTo = array(
'QuizQuestion' => array(
'className' => 'QuizQuestion',
'foreignKey' => 'question_id'
)
);
}
// quizzes_controller save()
public function save() {
if (!empty($this->data)) {
$this->Quiz->saveAll($this->data, array('validate' => 'first'));
}
// $this->redirect('/quizzes/view/'.$this->Quiz->id);
}
Check out the new CakePHP Questions site http://cakeqs.org and help others with
their CakePHP related questions.
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en