Uploaded image for project: 'Doctrine 2 - ORM'
  1. Doctrine 2 - ORM
  2. DDC-2424

Removing an inherited entity via a delete cascade constraint does not remove the parent row

    Details

    • Type: Bug
    • Status: Awaiting Feedback
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 2.3.3, 2.4.6
    • Fix Version/s: None
    • Component/s: None
    • Environment:
      Mysql 5.1.66 / Symfony 2.2.1

      Description

      For a parent class:

      /**
       * @ORM\Entity
       * @ORM\Table(name="Base")
       * @ORM\InheritanceType("JOINED")
       * @ORM\DiscriminatorColumn(name="discr", type="string")
       * @ORM\DiscriminatorMap({"child1" = "Child1", "child2" = "Child2"})
       */
      

      and simple Child1 & Child2 entities.

      With another entity (let's call it ExternalEntity) having a bidirectional OneToOne relation owned by Child1:

      class Child1 extends Base
      {
        /**
         * @ORM\OneToOne(targetEntity="ExternalEntity", inversedBy="xxx")
         * @ORM\JoinColumn(onDelete="CASCADE", nullable=false)
         */
         private theForeignKey;
      }
      

      Enough for the context.
      The symptoms:

      $em->remove(instanceOfExternalEntity);

      removes the ExternalEntity row and the Child1 row. But a dangling row in the Base table is still there for the now inexistent Child1 instance.

      Though, a manual delete of either the associated Child1 OR Base row and then the ExternalEntity works.

      The problem with the cascading deletion of the parent seems to be only present when deleting through a MYSQL cascading delete from another row which has a foreign key on a child. (Not tested with a foreign key on the parent though)

        Activity

        xaapyks Bruno Jacquet created issue -
        xaapyks Bruno Jacquet made changes -
        Field Original Value New Value
        Description For a parent class:

        /**
         * @ORM\Entity
         * @ORM\Table(name="Base")
         * @ORM\InheritanceType("JOINED")
         * @ORM\DiscriminatorColumn(name="discr", type="string")
         * @ORM\DiscriminatorMap({"child1" = "Child1", "child2" = "Child2"})
         */

        and simple Child1 & Child2 entities.

        With another entity (let's call it ExternalEntity) having a bidirectional OneToOne relation owned by Child1:

        class Child1 extends Base
        {
          /**
           * @ORM\OneToOne(targetEntity="ExternalEntity", inversedBy="xxx")
           * @ORM\JoinColumn(onDelete="CASCADE", nullable=false)
           */
           private theForeignKey;
        }

        Enough for the context.
        The symptoms:

        $em->remove(instanceOfExternalEntity); removes the ExternalEntity row and the Child1 row. But a dangling row in the Base table is still there for the now inexistent Child1 instance.

        Though, a manual delete of either the associated Child1 OR Base row and then the ExternalEntity works.

        THe problem with the cascading deletion of the parent seems to be only present when deleting through a MYSQL cascading delete from another row which has a foreign key on a child. (Not tested with a foreign key on the parent though)

        For a parent class:

        /**
         * @ORM\Entity
         * @ORM\Table(name="Base")
         * @ORM\InheritanceType("JOINED")
         * @ORM\DiscriminatorColumn(name="discr", type="string")
         * @ORM\DiscriminatorMap({"child1" = "Child1", "child2" = "Child2"})
         */

        and simple Child1 & Child2 entities.

        With another entity (let's call it ExternalEntity) having a bidirectional OneToOne relation owned by Child1:

        class Child1 extends Base
        {
          /**
           * @ORM\OneToOne(targetEntity="ExternalEntity", inversedBy="xxx")
           * @ORM\JoinColumn(onDelete="CASCADE", nullable=false)
           */
           private theForeignKey;
        }

        Enough for the context.
        The symptoms:

        $em->remove(instanceOfExternalEntity); removes the ExternalEntity row and the Child1 row. But a dangling row in the Base table is still there for the now inexistent Child1 instance.

        Though, a manual delete through $em->createQuery() of either the associated Child1 OR Base row and then the ExternalEntity works.

        The problem with the cascading deletion of the parent seems to be only present when deleting through a MYSQL cascading delete from another row which has a foreign key on a child. (Not tested with a foreign key on the parent though)

        ocramius Marco Pivetta made changes -
        Description For a parent class:

        /**
         * @ORM\Entity
         * @ORM\Table(name="Base")
         * @ORM\InheritanceType("JOINED")
         * @ORM\DiscriminatorColumn(name="discr", type="string")
         * @ORM\DiscriminatorMap({"child1" = "Child1", "child2" = "Child2"})
         */

        and simple Child1 & Child2 entities.

        With another entity (let's call it ExternalEntity) having a bidirectional OneToOne relation owned by Child1:

        class Child1 extends Base
        {
          /**
           * @ORM\OneToOne(targetEntity="ExternalEntity", inversedBy="xxx")
           * @ORM\JoinColumn(onDelete="CASCADE", nullable=false)
           */
           private theForeignKey;
        }

        Enough for the context.
        The symptoms:

        $em->remove(instanceOfExternalEntity); removes the ExternalEntity row and the Child1 row. But a dangling row in the Base table is still there for the now inexistent Child1 instance.

        Though, a manual delete through $em->createQuery() of either the associated Child1 OR Base row and then the ExternalEntity works.

        The problem with the cascading deletion of the parent seems to be only present when deleting through a MYSQL cascading delete from another row which has a foreign key on a child. (Not tested with a foreign key on the parent though)

        For a parent class:

        {code}
        /**
         * @ORM\Entity
         * @ORM\Table(name="Base")
         * @ORM\InheritanceType("JOINED")
         * @ORM\DiscriminatorColumn(name="discr", type="string")
         * @ORM\DiscriminatorMap({"child1" = "Child1", "child2" = "Child2"})
         */
        {code}

        and simple Child1 & Child2 entities.

        With another entity (let's call it ExternalEntity) having a bidirectional OneToOne relation owned by Child1:

        {code}
        class Child1 extends Base
        {
          /**
           * @ORM\OneToOne(targetEntity="ExternalEntity", inversedBy="xxx")
           * @ORM\JoinColumn(onDelete="CASCADE", nullable=false)
           */
           private theForeignKey;
        }
        {code}

        Enough for the context.
        The symptoms:

        {code}$em->remove(instanceOfExternalEntity);{code} removes the ExternalEntity row and the Child1 row. But a dangling row in the Base table is still there for the now inexistent Child1 instance.

        Though, a manual delete of either the associated Child1 OR Base row and then the ExternalEntity works.

        The problem with the cascading deletion of the parent seems to be only present when deleting through a MYSQL cascading delete from another row which has a foreign key on a child. (Not tested with a foreign key on the parent though)

        beberlei Benjamin Eberlei made changes -
        Status Open [ 1 ] Awaiting Feedback [ 10000 ]
        korotovsky Dmitry Korotovsky made changes -
        Affects Version/s 2.4.6 [ 10723 ]
        korotovsky Dmitry Korotovsky made changes -
        Labels inheritance postgresql

          People

          • Assignee:
            beberlei Benjamin Eberlei
            Reporter:
            xaapyks Bruno Jacquet
          • Votes:
            3 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated: