Cakephp HasMany + SaveAll不工作 [英] Cakephp HasMany + SaveAll doesnt work
本文介绍了Cakephp HasMany + SaveAll不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图做一个hasmany saveall()但它不工作。
Im trying to do a hasmany saveall() but it does not work.
我有一个模型Carmodel hasMany CarmodelsImage
当我尝试保存,传递的数组为:
I have a Model Carmodel hasMany CarmodelsImage When i try to save, the array passed is:
[CarmodelsImage] => Array
(
[0] => Array
(
[name] => teste
[carmodel_id] => 1
)
)
< > request-> data),但不起作用。
In the controller i have $this->Carmodel->saveAll($this->request->data) but it does not work.
我需要一些帮助。
感谢
推荐答案
您请求的数据需要是一个数组,如下面的代码:
Your requested data needs to be an array like in the following code:
Array
(
[Carmodel] => Array
(
//Carmodel fields here
)
[CarmodelsImage] => Array
(
[0] => Array
(
[name] => teste
[carmodel_id] => 1
)
[1] => Array
(
[name] => abc
[carmodel_id] => 2
)
..........
)
)
$this->Carmodel->saveAll($this->request->data, array('deep' => true));
您必须使用'deep'=> true
选项与saveAll()方法,同时保存关联的模型详细信息。
You have to use 'deep' => true
option with saveAll() method while saving associated models details.
这篇关于Cakephp HasMany + SaveAll不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文