Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1504

Cascade remove in OneToMany relation doesn't work

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Incomplete
    • Affects Version/s: 2.1.2
    • Fix Version/s: 2.2.3
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None
    • Environment:
      Ubuntu 10.10, syfmony 2.0.4

      Description

      I have two entities :

      class Structure
      {
          // Id and other variables
      
          /**
           * @var ArrayCollection $employees liste des employés d'une structure
           *
           * @ORM\OneToMany(targetEntity="Uriae\EmployeeBundle\Entity\Employee", mappedBy="structure", cascade={"all"})
           */
          private $employees;
      }
      
      class Employee
      {
          // Id and other variables
      
          /**
           * @var integer $structure
           *
           * @ORM\ManyToOne(targetEntity="Uriae\StructureBundle\Entity\Structure",inversedBy="employees")
           */
          private $structure;
      }
      

      The problem is when I used tests and I wan't remove a Structure the Employees aren't removed.

      // Doesn't work
      $em->remove($structure);
      $em->flush();
      
      // Bad solution but it works
      $em->remove($structure);
      $em->flush();
      foreach ($employee as $employees)
      {
          $em->remove($employee);
      }
      $e->flush();
      

        Activity

        Gaetan Rousseau created issue -
        Benjamin Eberlei made changes -
        Field Original Value New Value
        Description I have two entities :

        class Structure
        {
            // Id and other variables

            /**
             * @var ArrayCollection $employees liste des employés d'une structure
             *
             * @ORM\OneToMany(targetEntity="Uriae\EmployeeBundle\Entity\Employee", mappedBy="structure", cascade={"all"})
             */
            private $employees;
        }

        class Employee
        {
            // Id and other variables

            /**
             * @var integer $structure
             *
             * @ORM\ManyToOne(targetEntity="Uriae\StructureBundle\Entity\Structure",inversedBy="employees")
             */
            private $structure;
        }

        The problem is when I used tests and I wan't remove a Structure the Employees aren't removed.

        // Doesn't work
        $em->remove($structure);
        $em->flush();

        // Bad solution but it works
        $em->remove($structure);
        $em->flush();
        foreach ($employee as $employees)
        {
            $em->remove($employee);
        }
        $e->flush();
        I have two entities :

        {code}
        class Structure
        {
            // Id and other variables

            /**
             * @var ArrayCollection $employees liste des employés d'une structure
             *
             * @ORM\OneToMany(targetEntity="Uriae\EmployeeBundle\Entity\Employee", mappedBy="structure", cascade={"all"})
             */
            private $employees;
        }

        class Employee
        {
            // Id and other variables

            /**
             * @var integer $structure
             *
             * @ORM\ManyToOne(targetEntity="Uriae\StructureBundle\Entity\Structure",inversedBy="employees")
             */
            private $structure;
        }
        {code}

        The problem is when I used tests and I wan't remove a Structure the Employees aren't removed.

        {code}
        // Doesn't work
        $em->remove($structure);
        $em->flush();

        // Bad solution but it works
        $em->remove($structure);
        $em->flush();
        foreach ($employee as $employees)
        {
            $em->remove($employee);
        }
        $e->flush();
        {code}
        Benjamin Eberlei made changes -
        Attachment DDC1504GitlessTest.php [ 11136 ]
        Benjamin Eberlei made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 2.2.3 [ 10196 ]
        Resolution Incomplete [ 4 ]
        Benjamin Eberlei made changes -
        Workflow jira [ 13209 ] jira-feedback [ 15122 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback [ 15122 ] jira-feedback2 [ 16986 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback2 [ 16986 ] jira-feedback3 [ 19239 ]

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Gaetan Rousseau
          • Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: