Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-827

Class Table Inheritance is broken when child classes have the same properties

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Critical Critical
    • Resolution: Invalid
    • Affects Version/s: 2.0-BETA4
    • Fix Version/s: None
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      I create one Superclass and several Subclasses. The subclasses have properties with the same name (but as I also want to have Subclasses without these properties, this is the only elegant construction), in this example "name".

      Now when I select the Superclass, I get all Subclass entities, but the "name" property is not hydrated correctly:

      <?php
      
      namespace Entities;
      
      /**
       * @Entity
       * @InheritanceType("JOINED")
       * @DiscriminatorColumn(name="type", type="integer")
       * @DiscriminatorMap({ "1" = "Subclass1", "2" = "Subclass2" })
       */
      class Superclass
      {
          /** @Id @Column(type="integer") @GeneratedValue(strategy="AUTO") */
          public $id;
      }
      
      /** @Entity */
      class Subclass1 extends Superclass
      {
          /** @Column(type="string") */
          public $name;
      }
      
      /** @Entity */
      class Subclass2 extends Superclass
      {
          /** @Column(type="string") */
          public $name;
      }
      
      /* */
      
      $sub1 = new Subclass1;
      $sub1->name = 'sub1name';
      $em->persist($sub1);
      
      $sub2 = new Subclass2;
      $sub2->name = 'sub2name';
      $em->persist($sub2);
      
      $em->flush();
      $em->clear();
      
      $query = $em->createQuery('SELECT s FROM Entities\Superclass s');
      foreach ($query->execute() as $s) {
      	echo 'name = ' . $s->name . PHP_EOL;
      }
      

      Output:

      name = sub2name
      name = 
      

      The SQL however seems correct, both "name" columns are selected. This seems to be a bug in hydration.

        Activity

          People

          • Assignee:
            Roman S. Borschel
            Reporter:
            Nico Kaiser
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: