Symfony 4 when entity field change, change field in another entity

I have two entities for example:

class Dog
{

    /**
     * @var House
     *
     * @ORMManyToOne(targetEntity="House")
     * @ORMJoinColumns({
     *   @ORMJoinColumn(name="house_id", referencedColumnName="id")
     * })
     */
    private $house;
}

class House
{

     /**
     * @var ArrayCollection|null
     * @ORMManyToMany(targetEntity="Dog",cascade={"persist"})
     * @ORMJoinColumns({
     * @ORMJoinColumn(name="dog_id", referencedColumnName="id", nullable=true)
     * })
     */
    protected $dog;
}

I need to throw an event if field house in Entity Dog was update (set or remove) then add or remove field dog in Entity House.
Can anyone show me how do this ?

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *