title: Doctrine ArrayCollection remove element not working
body: <p>Even if the object is correctly updated it seems that the data is not persisted and I don't get it why.</p>
  
  <p>Here is my Entity:</p>
  
  <blockquote>
    <p>Article.php</p>
  </blockquote>
  
  <pre><code>/**
   * @var AttributeInArticle
   *
   * @ORM\OneToMany(
   *      targetEntity="XXX\DatabaseBundle\Entity\AttributeInArticle",
   *      mappedBy="article"
   * )
   */
  private $attributeInArticles;
  
  ....
  
  public function __construct()
  {
      $this-&gt;attributeInArticles = new ArrayCollection();
  }
  
  
  /**
   * @return AttributeInArticle
   */
  public function getAttributeInArticles()
  {
      return $this-&gt;attributeInArticles;
  }
  
  public function addAttributeInArticle(AttributeInArticle $attributeInArticles)
  {
      $this-&gt;attributeInArticles[] = $attributeInArticles;
  
      return $this;
  }
  
  public function removeAttributeInArticle(AttributeInArticle $attributeInArticles)
  {
      $this-&gt;attributeInArticles-&gt;removeElement($attributeInArticles);
  }
  </code></pre>
  
  <blockquote>
    <p>AttributeInArticle.php</p>
  </blockquote>
  
  <pre><code>/**
   * @var  Attribute
   *
   * @ORM\ManyToOne(
   *      targetEntity="XXX\DatabaseBundle\Entity\Attribute",
   *      inversedBy="attributeInArticles"
   * )
   * @ORM\JoinColumns({
   *     @ORM\JoinColumn(
   *          name="attribute_id",
   *          referencedColumnName="id")
   * })
   */
  private $attribute;
  
  /**
   * @var Article
   *
   * @ORM\ManyToOne(
   *      targetEntity="XXX\DatabaseBundle\Entity\Article",
   *      inversedBy="attributeInArticles"
   * )
   * @ORM\JoinColumns({
   *       @ORM\JoinColumn(
   *          name="article_id",
   *          referencedColumnName="id"
   *      )
   * })
   *
   */
  private $article;
  
  /**
   * @return Attribute
   */
  public function getAttribute()
  {
      return $this-&gt;attribute;
  }
  
  /**
   * @param Attribute $attribute
   */
  public function setAttribute($attribute)
  {
      $this-&gt;attribute = $attribute;
  }
  
  + getter &amp; setter for $article
  </code></pre>
  
  <p>And in the controller I am calling it like this:</p>
  
  <pre><code>$article-&gt;removeAttributeInArticle($attributeInArticle);
  </code></pre>
  
  <p>If I dumpthe $article object before and after the remove action the $article object has the corect data in it. That means that $attributeInArticle was removed.</p>
  
  <p>But for some reason it does not persist this data.</p>