0
对于多对多关系,所有选择都会有多大的限制?我有这样的设计:限制多对多与CakePHP一起使用
表调查有许多表调查部分。表格调查部分有许多问题。表格问题有许多表格可能的回应。
如果我这样做了调查表:
$this->loadModel('Survey');
$this->Survey->recursive = 2;
$getSurvey = $this->Survey->find('all');
它只会去尽可能的问题表,但带回的可能的响应表。但是,如果我查询Survey Sections表格,它会将所有内容都带回。这是我的代码问题还是限制搜索的深度?
这里是我的模型:
<?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(
);
}
当您尝试'$ this-> Survey-> recursive = 3;'而不是2时,您的代码会做什么? – Holt
我的印象是这个值只能到2:http://book.cakephp.org/2.0/en/models/model-attributes.html#recursive,但你是对的,将它改为3有效。 – jason
我不太确定我自己,这就是为什么我没有把它作为答案发布(是否有效?)。我认为CakePHP书籍仅仅为特定案例展示了一个例子。 – Holt