Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
CakePHP中的可包含行为未按预期工作_Cakephp_Cakephp Model - Fatal编程技术网

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
模型相关联。我非常确定它将与这些关联一起工作。没有,这些关联彼此距离太远。