Cakephp HasMany + SaveAll doesnt work

匿名 (未验证) 提交于 2019-12-03 09:52:54

问题:

Im trying to do a hasmany saveall() but it does not work.

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             )     ) 

In the controller i have $this->Carmodel->saveAll($this->request->data) but it does not work.

I need some help.

I know this question was already posted but I read every answers and it not work.

Thanks

回答1:

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)); 

You have to use 'deep' => true option with saveAll() method while saving associated models details.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!