我的数据库表格如下所示:
chapters
********
id
name
chapter_id
workpackages
*******
id
name
chapter_id
requirements
******
id
name
workpackage_id
project_id
projects
*******
id
name
我的模型关联看起来像这样:
Chapter Model
*************
public $hasMany= array(
'Workpackage' => array(
'className' => 'Workpackage'
'foreignKey' => 'chapter_id'
'Chapter' => array(
'className' => 'Chapter'
'foreignKey' => 'parent_id'
)
);
Workpackage Model
************
public $belongsTo = array(
'Chapter' => array(
'className' => 'Chapter'
'foreignKey' => 'chapter_id'
)
);
public $hasMany = array(
'Requirement' => array(
'className' => 'Requirement'
'foreignKey' => 'workpackage_id'
)
);
Requirement Model
************
public $belongsTo = array(
'Project' => array(
'className' => 'Project'
'foreignKey' => 'project_id'
)
'Workpackage' => array(
'className' => 'Workpackage'
'foreignKey' => 'workpackage_id'
)
);
Project Model
************
public $hasMany= array(
'Requirement' => array(
'className' => 'Requirement'
'foreignKey' => 'project_id'
)
);
我已使用以下方法将四个模型中的每一个设置为使用包含:
public $actsAs = array('Containable');
在我的章节/索引中,我想展示所有章节的工作包和一个特定项目的章节 到目前为止我尝试过的所有内容都发布了数据库错误。
我的ChaptersController索引函数的当前状态如下所示:
$chapters = $this->Chapter->find('threaded', array(
'conditions' => array('Requirement.id' => $id),
'contain' => array('Workpackage' => 'Chapter.name')
));
有什么问题?