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.
... from the documentation.
I have got same issue and I have solved it by update $user in
preUpdate()
then schedule an extra update: