删除“旧”与 saveAll 的关联
我有一个关联问题,即一个“有很多”链接的项目。项目编辑页面包含项目本身的字段和一些关联链接的字段:
echo $form->input('Link.0.url');
echo $form->input('Link.1.url');
echo $form->input('Link.2.url');
在项目控制器中,我使用 $this->Project->saveAll($this->data),它保存项目和三个关联的链接。美好的。现在,在更新项目时,我希望能够删除一些链接。我想保持简单并使用 jQuery 删除所有 Link.n.* 。不幸的是,这并没有按预期工作:使用 saveAll 后,删除的关联仍然存在,即使它不再在 $this->data 中给出。
CakePHP 在保存关联方面非常具体。遗憾的是我找不到有关删除它们的信息。我希望有人理解我的问题并知道该怎么做。
I have a problem with assocations, i.e. a Project which "hasMany" Links. The project edit page has fields for the Project itself and some for associated Links:
echo $form->input('Link.0.url');
echo $form->input('Link.1.url');
echo $form->input('Link.2.url');
In the Project controller I use $this->Project->saveAll($this->data), which saves the Project and three associated links. Fine. Now while updating Projects I want to be able to delete some links. I want to keep it simple and remove all Link.n.* using jQuery for example. Unfortunately this doesn't work as expected: The removed association still exists after using saveAll, even though it is not given in $this->data anymore.
CakePHP is very specific in saving associations. Sadly I cannot find something about removing them. I hope somebody understands my problem and has an idea what to do.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果它已经在数据库中,您将需要使用delete()或deleteAll()
if it is already in the database you will need to use delete() or deleteAll()