将数据保存/创建到关联 table 无效
Saving / Creating data to associated table is not working
我有三个table,
Authors
Stories
Details
故事和详细信息与作者相关联,具有 hasOne 关系。
下面是我的 AuthorsController 中的代码
function add(){
if($this->request->is('POST')){
$author = $this->Authors->newEntity($this->request->data,
['associated' => ['Stories', 'Details'], 'validate' => false]
);
$this->Authors->save($author);
}
}
这只保存了作者 table 中的数据,而不是其他两个 table 中的数据。
下面是我在 $this->request->data
中的数据
'Authors' => [
'name' => 'Bikash'
'Age' => '22'
'stories' => [
'name' => 'Life Without the L'
'gener_id' => 5
]
'details' => [
'qualification' => 'XYZ'
'biography'
]
];
我错过了什么?
您使用了错误的 属性 名称,stories
和 details
将无法使用。
hasOne
关联的默认关联 属性 名称,是关联别名的带下划线的 单数 变体,因此对于 Stories
将 story
,对于 Details
,它将是 detail
。
另见
我有三个table,
Authors
Stories
Details
故事和详细信息与作者相关联,具有 hasOne 关系。
下面是我的 AuthorsController 中的代码
function add(){
if($this->request->is('POST')){
$author = $this->Authors->newEntity($this->request->data,
['associated' => ['Stories', 'Details'], 'validate' => false]
);
$this->Authors->save($author);
}
}
这只保存了作者 table 中的数据,而不是其他两个 table 中的数据。 下面是我在 $this->request->data
中的数据'Authors' => [
'name' => 'Bikash'
'Age' => '22'
'stories' => [
'name' => 'Life Without the L'
'gener_id' => 5
]
'details' => [
'qualification' => 'XYZ'
'biography'
]
];
我错过了什么?
您使用了错误的 属性 名称,stories
和 details
将无法使用。
hasOne
关联的默认关联 属性 名称,是关联别名的带下划线的 单数 变体,因此对于 Stories
将 story
,对于 Details
,它将是 detail
。
另见