Wednesday, 15 June 2011

Limit to how deep a Many-To-Many will go with CakePHP -



Limit to how deep a Many-To-Many will go with CakePHP -

is there limit how deep select go many-to-may relationship? have design this:

table survey has many table survey sections. table survey sections have many questions. table questions have many table possible responses.

if survey table:

$this->loadmodel('survey'); $this->survey->recursive = 2; $getsurvey = $this->survey->find('all');

it go far questions table bring possible responses table. but, if query survey sections table, brings back. issue code or limit how deep search go?

here models:

<?php app::uses('appmodel', 'model'); class survey extends appmodel { public $validate = array( ); public $belongsto = array( ); public $hasmany = array( 'surveysection' => array( 'classname' => 'surveysection', 'foreignkey' => 'surveys_id', ), ); } <?php app::uses('appmodel', 'model'); class surveysection extends appmodel { public $validate = array( ); public $belongsto = array( ); public $hasmany = array( 'question' => array( 'classname' => 'question', 'foreignkey' => 'survey_section_id', ), ); } <?php app::uses('appmodel', 'model'); class question extends appmodel { public $validate = array( ); public $belongsto = array( ); public $hasmany = array( 'possibleresponse' => array( 'classname' => 'possibleresponse', 'foreignkey' => 'questions_id', ), ); } <?php app::uses('appmodel', 'model'); class possibleresponse extends appmodel { public $validate = array( ); public $belongsto = array( ); }

you should utilize $this->survey->recursive = 3;.

as said in comment, illustration @ http://book.cakephp.org/2.0/en/models/model-attributes.html#recursive bit misleading because show illustration specific case. in fact can go far want when fetching data.

cakephp cakephp-2.1 cakephp-2.3 cakephp-appmodel

No comments:

Post a Comment