Doctrine: can't removeElement from inverse side of the relation

亡梦爱人 提交于 2019-12-25 08:05:00

问题


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:

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?

来源:https://stackoverflow.com/questions/41058460/doctrine-cant-removeelement-from-inverse-side-of-the-relation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!