DDC-796: Inheritance Discriminator mapping fails when the parent class is after a subclass alphabetically #982

Closed
opened 2026-01-22 12:58:02 +01:00 by admin · 5 comments
Owner

Originally created by @doctrinebot on GitHub (Sep 9, 2010).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user gnuffo1:

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:

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.

Originally created by @doctrinebot on GitHub (Sep 9, 2010). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user gnuffo1: 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.
admin added the Bug label 2026-01-22 12:58:02 +01:00
admin closed this issue 2026-01-22 12:58:04 +01:00
Author
Owner

@doctrinebot commented on GitHub (Sep 10, 2010):

Comment created by @beberlei:

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.

@doctrinebot commented on GitHub (Sep 10, 2010): Comment created by @beberlei: 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.
Author
Owner

@doctrinebot commented on GitHub (Sep 10, 2010):

Comment created by gnuffo1:

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:

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.

@doctrinebot commented on GitHub (Sep 10, 2010): Comment created by gnuffo1: 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.
Author
Owner

@doctrinebot commented on GitHub (Sep 10, 2010):

Comment created by gnuffo1:

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.

@doctrinebot commented on GitHub (Sep 10, 2010): Comment created by gnuffo1: 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.
Author
Owner

@doctrinebot commented on GitHub (Nov 16, 2010):

Comment created by @beberlei:

This issue was fixed in another ticket.

@doctrinebot commented on GitHub (Nov 16, 2010): Comment created by @beberlei: This issue was fixed in another ticket.
Author
Owner

@doctrinebot commented on GitHub (Nov 16, 2010):

Issue was closed with resolution "Duplicate"

@doctrinebot commented on GitHub (Nov 16, 2010): Issue was closed with resolution "Duplicate"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#982