在preUpdate事件列表中删除实体 [英] removing entities in preUpdate event lister

查看:118
本文介绍了在preUpdate事件列表中删除实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个实体的 preUpdate 监听器,我进行一些计算,设置值等。

I have a preUpdate listener for an Entity where I do some calculations, set values etc.

那个听众我想删除一些其他相关的实体,但这似乎不被实体经理刷新。如何实现这一点?

In that listener I would like to remove some other related entities, but this does not seem to be flushed by the entity manager. How can I go about achieving this?

推荐答案

根据Doctrine2 docs

According to the Doctrine2 docs:


更改更新的实体的关联在
这个事件中是不允许的,因为Doctrine不能保证在刷新操作的这一点处正确处理
引用完整性。

Changes to associations of the updated entity are never allowed in this event, since Doctrine cannot guarantee to correctly handle referential integrity at this point of the flush operation.

这意味着您不应该在 preUpdate 事件处理期间弄乱实体。建议您使用实体管理器将您的逻辑移至服务层。编写一个更新您的权限的具体方法,并在其中执行所有复杂的内容。实体经理的一个很好的例子是FOSUserBundle的 UserManager

Which means you shouldn't mess with the entities during the preUpdate event handling. I suggest you move your logic up to the service layer by using an entity manager. Write a specific method for updating your entitty and do all the complex stuff there. A nice example of an entity manager would be the FOSUserBundle's UserManager

这篇关于在preUpdate事件列表中删除实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆