当 orphanRemoval 设置为 true 时,Doctrine2 中 postPersist、postRemove 事件的触发顺序是什么?
我有实体 Order
与第二个实体 File
具有 @OneToOne
关系,关系的 orphanRemoval
属性设置为 真实。
现在,在 postRrmove
事件中,在删除 File
实体后触发,我正在删除相关文件形式的文件系统,在 postPersist
事件中,我将上传的文件移动到目标地点。
我想知道,当使用 File
实体的新实例更新 Order
实体时,触发 postPersist
和 postRemove< 的顺序是什么/code> 事件(在
orphanRemoval
上下文中)?
因为如果先触发 postPersist
,新的 File
实例与旧的文件名相同,上传的文件将覆盖旧的文件,并且 postRemove
事件将删除它。女巫是不需要的:)
I have entity Order
witch has @OneToOne
relation to second entity File
, relation has orphanRemoval
attribute set to true
.
Now on postRrmove
event, fired after removal of File
entity I'm deleting related file form filesystem, on postPersist
event I move uploaded file to destination location.
I'm wondering, when updating Order
entity with new instance of File
entity, what is an order of firing postPersist
and postRemove
events (in orphanRemoval
context)?
Because if postPersist
is fired first, nad new File
instance has same filename as old one, the uploaded file will override old one, and postRemove
event will delete it. Witch is unwanted :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现,触发的第一个事件是新实体的
postPersist
,然后是旧实体的postRemove
。I figured it out, the first event fired is
postPersist
of new entity, and thenpostRemove
of old entity.