title: Doctrine 2.1 - Removing from collection
body: <p>I am trying to remove comments from a parent entity, I remember doing this on my last website but now it's not working..</p>
  
  <p>My entity - users</p>
  
  <pre><code>namespace Application\Entities;
  
  use Doctrine\ORM\Mapping AS ORM,
      Doctrine\Common\Collections\ArrayCollection;
  
  /**
   * Loan
   *
   * @ORM\Table(name="users")
   * @ORM\Entity
   */
  class Users{
  
      /**
       * @var integer $id
       *
       * @ORM\Column(type="integer", nullable=false)
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="IDENTITY")
       */
      private $id;
  
  
      /**
       * @var string $username
       *
       * @ORM\Column(type="string", length=45, nullable=false)
       */
      private $username;
  
      /**
       * @var ArrayCollection
       *
       * @ORM\OneToMany(targetEntity="Comments", mappedBy="author", cascade={"persist", "remove"})
       */
      private $comments;
  
      public function getComments(){
  
            return $this-&gt;comments;              
  
      }
  </code></pre>
  
  <p>and my comments table:</p>
  
  <pre><code>    namespace Application\Entities;
  
      use Doctrine\ORM\Mapping AS ORM,
          Doctrine\Common\Collections\ArrayCollection;
  
  /**
   * Loan
   *
   * @ORM\Table(name="comments")
   * @ORM\Entity
   */
  class Comments{
  
      /**
       * @var integer $id
       *
       * @ORM\Column(type="integer", nullable=false)
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="IDENTITY")
       */
      private $id;
  
  
      /**
       * @var integer $user_id
       *
       * @ORM\Column(type="integer", length=15, nullable=false)
       */
      private $user_id
  
      /**
       * @var Loan
       *
       * @ORM\ManyToOne(targetEntity="Users", inversedBy="comments",cascade={"persist"})
       * @ORM\JoinColumns({
       *   @ORM\JoinColumn(name="user_id", referencedColumnName="id")
       * })
       */
      private $author;
  </code></pre>
  
  <p>This is fine, it works and I get all collections called comments in the users repository..</p>
  
  <p>Now, I usually do this when I need to delete:</p>
  
  <pre><code>$commentToDelete = $this-&gt;em-&gt;getRepository('Entities\Comments')-&gt;findOneById(375);
  $userResults = $this-&gt;em-&gt;getRepository('Entities\Users')-&gt;findOneById(23);
  $userResults-&gt;getComments()-&gt;removeElement($commentToDelete);
  $this-&gt;em-&gt;flush();
  </code></pre>
  
  <p>Nothing deletes, neither it throws an exception to tell me it hasn't.</p>
  
  <p>I doctrine flushed it too, checked the db, and it's still there..</p>
  
  <p><strong>UPDATE:</strong><br>
  Straight after I removeElement, I looped through the user id = 23 dataset, and the comment data for id375 is not there...  so it removed it from the collection but not from the DB, and I thought <code>$em-&gt;flush()</code> is supposed to do this?</p>
  
  <p>Please advise<br>
  Thanks</p>