Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-796

Inheritance Discriminator mapping fails when the parent class is after a subclass alphabetically

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Duplicate
    • Affects Version/s: 2.0-BETA4
    • Fix Version/s: 2.0-RC1
    • Component/s: Mapping Drivers
    • Security Level: All
    • Labels:
      None
    • Environment:
      PHP 5.3, PDO_MYSQL

      Description

      If I have a class called AbstractPage, with this single table inheritance mapping linking to the folllowing classes (Page, Article, Review), then it works fine:

      <discriminator-column name="discr" type="string" />
      <discriminator-map>
      <discriminator-mapping value="page" class="Page" />
      <discriminator-mapping value="article" class="Article" />
      <discriminator-mapping value="review" class="Review" />
      </discriminator-map>

      If however I rename the classes to the Zend framework format, within modules (Default_Model_AbstractPage, Default_Model_Page, Article_Model_Article, Article_Model_Review), then because Article is before Default, then the schema tool gets confused and throws an error - [Doctrine\DBAL\Schema\SchemaException] The table with name 'pages' already exists. Everything else is the same but the class names.

      I have attached examples of this both working and nonworking with the different naming schemes. As you can see everything else is the same.

      1. nonworking.rar
        3 kB
        Daniel Moore
      2. working.rar
        3 kB
        Daniel Moore

        Activity

        Hide
        Benjamin Eberlei added a comment -

        if yo uspecify class="page" the class has to be called Page, not Default_Model_Page. You have to change the mapping to:

        <discriminator-column name="discr" type="string" />
        <discriminator-map>
        <discriminator-mapping value="page" class="Default_Model_Page" />
        <discriminator-mapping value="article" class="Default_Model_Article" />
        <discriminator-mapping value="review" class="Default_Model_Review" />
        </discriminator-map>
        

        You cannot re-use the mapping for different classes, it has to be bound specifically to an exisiting class.

        Show
        Benjamin Eberlei added a comment - if yo uspecify class="page" the class has to be called Page, not Default_Model_Page. You have to change the mapping to: <discriminator-column name= "discr" type= "string" /> <discriminator-map> <discriminator-mapping value= "page" class= "Default_Model_Page" /> <discriminator-mapping value= "article" class= "Default_Model_Article" /> <discriminator-mapping value= "review" class= "Default_Model_Review" /> </discriminator-map> You cannot re-use the mapping for different classes, it has to be bound specifically to an exisiting class.
        Hide
        Daniel Moore added a comment -

        I probably wasn't being explicit enough - when I said I rename the classes I also meant that I renamed them in all of the mapping, so I've got this:

        <discriminator-column name="discr" type="string" />
        <discriminator-map>
        <discriminator-mapping value="page" class="Default_Model_Page" />
        <discriminator-mapping value="article" class="Article_Model_Article" />
        <discriminator-mapping value="review" class="Article_Model_Review" />
        </discriminator-map>

        And I've also renamed the mapping files themselves from Page.dcm.xml to Default_Model_Page.dcm.xml and so on. Still doesn't work.

        Show
        Daniel Moore added a comment - I probably wasn't being explicit enough - when I said I rename the classes I also meant that I renamed them in all of the mapping, so I've got this: <discriminator-column name="discr" type="string" /> <discriminator-map> <discriminator-mapping value="page" class="Default_Model_Page" /> <discriminator-mapping value="article" class="Article_Model_Article" /> <discriminator-mapping value="review" class="Article_Model_Review" /> </discriminator-map> And I've also renamed the mapping files themselves from Page.dcm.xml to Default_Model_Page.dcm.xml and so on. Still doesn't work.
        Hide
        Daniel Moore added a comment -

        I've found a workaround for now. Move the subclasses into another folder (I've create a subfolder called "subclasses") and then add the second line:

        $driverImpl = new Doctrine\ORM\Mapping\Driver\XmlDriver(_DIR_ . '/mappings');
        $driverImpl->addPaths(array(_DIR_ . '/mappings/subclasses'));

        That way the second folder will get read after the parent classes.

        Show
        Daniel Moore added a comment - I've found a workaround for now. Move the subclasses into another folder (I've create a subfolder called "subclasses") and then add the second line: $driverImpl = new Doctrine\ORM\Mapping\Driver\XmlDriver(_ DIR _ . '/mappings'); $driverImpl->addPaths(array(_ DIR _ . '/mappings/subclasses')); That way the second folder will get read after the parent classes.
        Hide
        Benjamin Eberlei added a comment -

        This issue was fixed in another ticket.

        Show
        Benjamin Eberlei added a comment - This issue was fixed in another ticket.

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Daniel Moore
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: