title: (doctrine2 + symfony2) cascading remove : integrity constraint violation 1451
body: <p>First, sorry for my poor English...</p>
  
  <p>I got four entities : User, Application, Bundle &amp; Entity. Here are their relations (with cascading persist &amp; remove, see code below) :</p>
  
  <ul>
  <li>User <strong>1-n</strong> Application</li>
  <li>Application <strong>1-n</strong> Bundle</li>
  <li>Bundle <strong>1-n</strong> Entity</li>
  </ul>
  
  <p>It's working fine. But an User can have two of his entities as default, and I need to access them directly. </p>
  
  <p>So I add on User two fields, entity1 &amp; entity2, with a <strong>1-1</strong> relation. And now my app crashes :</p>
  
  <pre><code>An exception occurred while executing 'DELETE FROM bundle WHERE id = ?' with params {"1":13}:
  
  SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (`misc`.`entity`, CONSTRAINT `FK_E284468F1FAD9D3` FOREIGN KEY (`bundle_id`) REFERENCES `bundle` (`id`))
  </code></pre>
  
  <p>I tried several things, including those founded in <a href="https://stackoverflow.com/questions/12895724/doctrine-2-cascade-remove-doesnt-seem-to-be-working">this post</a>, but I wasn't able to fix it.</p>
  
  <p>Any help be welcome, thanks in advance.</p>
  
  <p><strong>EDIT :</strong> I need to point out that User->Entity relations are optionnal : User's entity1 &amp; entity2 can be null. The error happens even if they are null both.</p>
  
  <p>Here are my entities definitions :</p>
  
  <pre><code># User :
      /**
       * @ORM\OneToMany(targetEntity="\sfCommands\ContentBundle\Entity\Application", mappedBy="user", cascade={"remove"}, orphanRemoval=true)
       * @ORM\OrderBy({"name" = "ASC"})
       */
      protected $applications;
  
      /**
       * @ORM\OneToOne(targetEntity="\sfCommands\ContentBundle\Entity\Entity")
       * @ORM\JoinColumn(name="entity1_id", referencedColumnName="id")
       */
      private $entity1;
  
      /**
       * @ORM\OneToOne(targetEntity="\sfCommands\ContentBundle\Entity\Entity")
       * @ORM\JoinColumn(name="entity2_id", referencedColumnName="id")
       */
      private $entity2;
  
  #Application :
      /**
       * @ORM\OneToMany(targetEntity="\sfCommands\ContentBundle\Entity\Bundle", mappedBy="application", cascade={"remove"}, orphanRemoval=true)
       * @ORM\OrderBy({"name" = "ASC"})
       */
      protected $bundles;
  
      /**
       * @ORM\ManyToOne(targetEntity="\sfCommands\UserBundle\Entity\User", inversedBy="applications", cascade={"persist"})
       * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
       */
      protected $user;
  
  #Bundle :
      /**
       * @ORM\ManyToOne(targetEntity="\sfCommands\ContentBundle\Entity\Application", inversedBy="bundles", cascade={"persist"})
       * @ORM\JoinColumn(name="application_id", referencedColumnName="id")
       */
      protected $application;
  
      /**
       * @ORM\OneToMany(targetEntity="\sfCommands\ContentBundle\Entity\Entity", mappedBy="bundle", cascade={"remove"}, orphanRemoval=true)
       * @ORM\OrderBy({"name" = "ASC"})
       */
      protected $entitys;
  
  #Entity :
      /**
       * @ORM\ManyToOne(targetEntity="\sfCommands\ContentBundle\Entity\Bundle", inversedBy="entitys", cascade={"persist"})
       * @ORM\JoinColumn(name="bundle_id", referencedColumnName="id")
       */
      protected $bundle;
  </code></pre>