CakePHP中的可包含行为未按预期工作
我的数据库表如下所示:CakePHP中的可包含行为未按预期工作,cakephp,cakephp-model,Cakephp,Cakephp Model,我的数据库表如下所示: 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' => ar
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'
)
);
$chapters = $this->Chapter->find('threaded', array(
'conditions' => array('Requirement.id' => $id),
'contain' => array('Workpackage' => 'Chapter.name')
));
我的模型关联如下所示:
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'
)
);
$chapters = $this->Chapter->find('threaded', array(
'conditions' => array('Requirement.id' => $id),
'contain' => array('Workpackage' => 'Chapter.name')
));
我已通过以下方式将四个模型中的每一个设置为使用可控制行为:
public $actsAs = array('Containable');
在我的章节/索引中,我想显示所有章节及其工作包和一个特定项目的章节
到目前为止,我所做的一切都给我带来了数据库错误
my ChaptersController索引函数的当前状态如下所示:
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'
)
);
$chapters = $this->Chapter->find('threaded', array(
'conditions' => array('Requirement.id' => $id),
'contain' => array('Workpackage' => 'Chapter.name')
));
有什么问题吗?什么获取错误??SQLSTATE[42S22]:未找到列:未知列“Requirement.id”您需要将
Requirement
与Chapter
模型相关联。我非常确定它将与这些关联一起工作。没有,这些关联彼此距离太远。