CakePHP 中的数据应如何格式化以保存与 saveAll() 的三级关联?
我正在尝试构建一个“添加事件”页面。您可以添加多个“计划” - 每个计划都会在您设置的创建“日期”的日期/重复选项上运行计算。
-Event hasMany Schedule
-Schedule hasMany Date
-Schedule belongsTo Event
-Date belongsTo Schedule
问题是 - 数据需要如何格式化和/或如何读取字段名称以便能够 saveAll() 数据,以便日期也被保存。我目前正在使用它,因此它可以保存事件和时间表...但我无法让它也保存日期。
I'm trying to build an "Add an Event" page. You can add multiple "Schedules" - each of which will have calculations run on the date(s) / repeat options you set to create "Dates".
-Event hasMany Schedule
-Schedule hasMany Date
-Schedule belongsTo Event
-Date belongsTo Schedule
The question is - how does the data need to be formatted and/or how to the field names need to read in order to be able to saveAll() the data so Date(s) are also saved. I have it currently working so it saves the Event and the Schedule... but I can't get it to also save the Date(s).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
saveAll
仅适用于直接关联的模型。来自 CakePHP 文档:http://book.cakephp.org/view/1031/Saving-Your-Data
saveAll
only works on models that are directly associated. From the CakePHP doc:http://book.cakephp.org/view/1031/Saving-Your-Data
更新:请参阅标记为“答案”的答案。这个答案已经过时了。
根据这个 stackoverflow 答案。
即 - 必须手动执行,而不是在同一个“saveAll()”中。
UPDATE: See answer marked as 'answer'. This answer is out of date.
It appears it's not possible according to this stackoverflow answer.
ie - have to do it manually, not in the same "saveAll()".
实际上,从 CakePHP 2.1 开始,您可以使用 saveAll() 来完成。模型中的深度并不重要。在这里您可以看到新功能。
http://book.cakephp.org/2.0/en/appendices/new-features-in-cakephp-2-1.html#model-saveall-model-savelinked-model-validatelinked
Actually, since CakePHP 2.1, you can do it with saveAll(). Doesn't matter the deep level you have within your models. Here you can see the new features.
http://book.cakephp.org/2.0/en/appendices/new-features-in-cakephp-2-1.html#model-saveall-model-saveassociated-model-validateassociated