I have two entities for example:
class Dog
{
/**
* @var House
*
* @ORM\ManyToOne(targetEntity="House")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="house_id", referencedColumnName="id")
* })
*/
private $house;
}
class House
{
/**
* @var ArrayCollection|null
* @ORM\ManyToMany(targetEntity="Dog",cascade={"persist"})
* @ORM\JoinColumns({
* @ORM\JoinColumn(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 ?
You must call $dog->setHouse($this); from the addDog method. If you used the commandline then below class House would be generated for you.
Same thing counts for removeDog() method.