Doctrine: can't removeElement from inverse sid

2019-09-07 22:19发布

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?

0条回答
登录 后发表回答