Skip to content

Loading…

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

Closed
doctrinebot opened this Issue · 5 comments

2 participants

@doctrinebot

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 (DefaultModel_AbstractPage, Default_Model_Page, Article_Model_Article, Article_ModelReview), 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.

@doctrinebot

Comment created by @beberlei:

if yo uspecify class="page" the class has to be called Page, not DefaultModelPage. 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

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 DefaultModelPage.dcm.xml and so on. Still doesn't work.

@doctrinebot

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

Comment created by @beberlei:

This issue was fixed in another ticket.

@doctrinebot

Issue was closed with resolution "Duplicate"

@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot added this to the 2.0-RC1 milestone
@doctrinebot doctrinebot closed this
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.