0

I have a ManyToMany relation (an offer can have many banners, and a banner can belong to many offers). I don't understand why this works:

$banner->getOffers()->removeElement($this->offer);

But this doesn't:

$this->offer->getBanners()->removeElement($banner);

These are my entities:

Class Banner
{
    /**
     * @ORM\ManyToMany(targetEntity="AppBundle\Entity\Offer", inversedBy="banners")
     */
    private $offers;

    public function __construct()
    {
        $this->offers = new ArrayCollection();
    }
    public function getOffers(): Collection
    {
        return $this->offers;
    }
}

--

Class Offer 
{
    /**
     * @ORM\ManyToMany(targetEntity="AppBundle\Entity\Banner", mappedBy="offers")
     * @ORM\JoinColumn
     */
    private $banners;

    public function __construct()
    {
        $this->banners = new ArrayCollection();
    }

    public function getBanners(): Collection
    {
        return $this->banners;
    }
}

the removeElement() method returns true: enter image description here

I tried to persist $this->offer and even $banner, but nothing changed, the row isn't deleted from the banner_offer table.

I'm on Doctrine 2.7.1, Symfony 3.1.7

What am I doing wrong?

the_nuts
  • 5,634
  • 1
  • 36
  • 68
  • 3
    Doctrine only checks on the 'owning side' of an association: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/unitofwork-associations.html – LBA Dec 09 '16 at 10:44
  • 1
    I see... So removing the other side is useless. Thank you – the_nuts Dec 09 '16 at 10:48

0 Answers0