I want to select data of questions from quizdetails table. And data of questions will be join with answers table, too. So I using code php:
$questions = $this
->QuizDetails->find()
->contain([
'Questions' => function($q) {
return $q->contain(['Answers']);
}
])
->where(['QuizDetails.quiz_id' => $id]);
file AnswersTable:
$this->table('answers');
$this->belongsTo('Questions', [
'className' => 'Publishing.Questions',
'foreignKey' => 'question_id',
]);
file QuizDetailsTable:
$this->table('quiz_details');
$this->belongsTo('Questions', [
'className' => 'Publishing.Questions',
'foreignKey' => 'question_id',
]);
So, when i run it, through a error Questions is not associated with Answers
If I using:
$question = $this->Questions->find()->contain(['Answers'])
That is ok. Please help me to fix it.