Saturday, 15 August 2015

has many - find doesn't return associated model data cakePHP -



has many - find doesn't return associated model data cakePHP -

models question , answer

class question extends appmodel { public $name = "question"; public $usetable = "questions"; public $primarykey = 'question_id'; public $hasmany = array( 'answer' => array( 'classname' => 'answer', 'foreignkey' => 'question_id', 'dependent' => true ) ); } class reply extends appmodel { public $name = "answer"; public $usetable = "answers"; public $primarykey = 'answer_id'; public $belongsto = array( 'question' => array( 'classname' => 'question', 'foreignkey' => 'question_id', ) ); }

in database

answers answer_id question_id text

questions question_id skill_id text

in controller

$questions = $this->question->find('all', array('conditions' => array('skill_id' => $skills)));

doesn't homecoming me answers, returns me questions matches skill id.

i want fetch questions along there answers in single find query.

cakephp has-many multiple-tables model-associations belongs-to

No comments:

Post a Comment