PreUpdate实体symfony LifecycleCallbacks [英] PreUpdate entity symfony LifecycleCallbacks

查看:192
本文介绍了PreUpdate实体symfony LifecycleCallbacks的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个实体用户与实体产品有一个OneToMany关系。

$ b我有一个与Symfony的PreUpdate LifecycleCallbacks有点问题。
$ b

  class User {
/ **
* @ ORM\OneToMany(targetEntity =Product,mappedBy =formulario ,cascade = {persist,remove})
* /
private $ products;
}

class Product {
/ **
* @ ORM\ManyToOne(targetEntity =User,inversedBy =products)
* @ ORM\JoinColumn(name =user,referencedColumnName =id)
* /
private $ user;
}

我的问题是当我从用户添加或删除产品时。当我想要启动PreUpdate功能以在用户实体中进行一些更改时。但是,从用户更改实体产品时,PreUpdate不会触发。



非常感谢!!!

解决方案

不允许使用preUpdate侦听器更改相关实体。


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


...从文档


I have a little problem with the PreUpdate LifecycleCallbacks in Symfony.

I have an entity User with a OneToMany relation with an entity product.

class User{
     /**
     * @ORM\OneToMany(targetEntity="Product", mappedBy="formulario", cascade={"persist", "remove"})
     */
    private $products;
}

class Product{
     /**
     * @ORM\ManyToOne(targetEntity="User", inversedBy="products")
     * @ORM\JoinColumn(name="user", referencedColumnName="id")
     */
    private $user;
}

My problem is when I add or remove a product from the User. When this hapends I want to launch a PreUpdate function to make some changes in the User Entity. But the PreUpdate is not fire when changing the entity Product from the User.

Thanks a lot!!!

解决方案

Changing related entities is not allowed using a preUpdate listener.

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.

... from the documentation.

这篇关于PreUpdate实体symfony LifecycleCallbacks的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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