同时保存多个HABTM模型
因为我找不到很多关于同时保存两个具有HABTM关系的模型的信息。
我有一个订阅表格,可以在线订阅儿童。家长可以同时输入多个孩子和多个家长。因此,JS 可以添加更多文本框并使它们有效(Model.number.field
)
我想验证子项和管理器(不能使用父模型名称,因此父模型= 在本例中为经理):
if($this->Child->saveAll($this->data['Child'], array('validate' => 'only')) && ($this->Manager->saveAll($this->data['Manager'], array('validate' => 'only'))) ) { debug('表单有效!'); }
此代码仅在只有 1 个子级和 1 个管理器(=父级)时才有效。
如何同时保存这 2 个具有 HABTM 关系的模型?
这是值 $this->data
的调试:http://pastebin.com/ m6dtBzga
Since I can't find a lot of information on saving two models at the same time which have a HABTM relationship.
I have a subscribe form, to subscribe children online. Parents can enter multiple children and multiple parents at the same time. So a JS can add more textboxes and makes them cake valid (Model.number.field
)
I want to validate the children and the managers (can't use parent model name, so a parent = a manager in this case):
if($this->Child->saveAll($this->data['Child'], array('validate' => 'only')) && ($this->Manager->saveAll($this->data['Manager'], array('validate' => 'only'))) ) { debug('form is valid!'); }
This code only works when there is only 1 child and 1 manager (=parent).
How do I save these 2 models with a HABTM relationship at the same time?
This is a debug of the value $this->data
: http://pastebin.com/m6dtBzga
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从文档中:
为了保存单个模型的多个记录,$data需要是一个数字索引的记录数组,如下所示:
用于保存上述$data数组的命令如下所示:
http://book.cakephp.org/view/1031/Saving-Your-Data
From the documentation:
For saving multiple records of single model, $data needs to be a numerically indexed array of records like this:
The command for saving the above $data array would look like this:
http://book.cakephp.org/view/1031/Saving-Your-Data