mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Doctrine ORM 2.9: MappedSuperclass in entity hierarchy #6761
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @BenMorel on GitHub (Jun 16, 2021).
We have an entity hierarchy similar to:
This was working fine with Doctrine 2.8.
Since we upgraded to Doctrine 2.9 however,
bin/console doctrine:schema:validatestarted failing with:I tried adding a "fake" entry to the discriminator map for the abstract class:
But now Doctrine attempts to
JOINa non-existing table when loading an entity in the hierarchy:How can I fix this?
A solution would be to make the intermediate abstract class an entity, but this would mean that
$productwould be moved from leaf entities to a newAbstractProductInvoiceItemtable, which adds an extraJOINto every query, and would mean a rather scary migration to do.Is there a better solution? Or are MappedSuperclasses not allowed in the middle of an entity hierarchy anymore?
@greg0ire commented on GitHub (Jun 17, 2021):
This changed in #8378
@BenMorel commented on GitHub (Jun 17, 2021):
Thanks for the pointer, @greg0ire; do you know of any solution for this issue?
@greg0ire commented on GitHub (Jun 17, 2021):
I don't, I was just adding to this post because it might give you pointers as to who you might want to talk to about this, or whether this was deliberate or not. I think this might be worth a read too: https://github.com/doctrine/orm/pull/7825
Also, https://github.com/doctrine/orm/pull/8415 looks like it might fix your issue? I don't have a lot of time to help you right now, but you might have some helpful things to read in this repo's issues and PRs
@BenMorel commented on GitHub (Jun 17, 2021):
I tried the fix from #8415, but it does not seem to solve my issue I'm afraid :(
AFAICS, I still have to choose between:
@MappedSuperclassin the discriminator map, and getting an error indoctrine:schema:validateThank you again for the pointers, though! I appreciate it.
@beberlei commented on GitHub (Jun 17, 2021):
Its a bug this fails, i oversaw the mapped superclass case
@BenMorel commented on GitHub (Jun 17, 2021):
Glad to hear it, @beberlei! If you give me a hint as to how to fix it, maybe I can help?
@beberlei commented on GitHub (Jun 17, 2021):
Just check for isMappedSuperclass in SchemaValifator to avoif the error
@BenMorel commented on GitHub (Jun 18, 2021):
@beberlei Thank you, it works fine for
@MappedSuperclassby adding the! $class->isMappedSuperclasscheck here:I still, however, have a
[FAIL]when there is an abstract@Entityclass in the middle of the inheritance hierarchy. Why would we have to create an entry in the discriminator map for a non-instantiable class?Would you be OK with changing this for
! $class->reflClass->isAbstract()instead?@BenMorel commented on GitHub (Jul 10, 2021):
Ping @beberlei 🙂
@olsavmic commented on GitHub (Aug 4, 2021):
@beberlei We're having the very same issue. It does not make much sense to me to require abstract classes to be a part of the discriminator map.
If you feel like there is a reason to require it, let us know please. Otherwise I can prepare a PR with a fix :)
Thank you!
@olsavmic commented on GitHub (Aug 5, 2021):
I found your comment (https://github.com/doctrine/orm/issues/8736#issuecomment-853044536) and I even found a case when the behaviour is unexpected if the abstract class in the middle of hierarchy is not present (SchemaTool:183, relationship columns may not be created)
so it's not a BC break but rather a bug fix and this issue can be closedso my issue regarding the abstract class is resolved.Thank you! @beberlei
@BenMorel commented on GitHub (Aug 5, 2021):
@olsavmic Adding a fake entry for abstract classes does not fix all issues, please re-read the first post of this thread.
This issue cannot be closed!
@olsavmic commented on GitHub (Aug 5, 2021):
@BenMorel I'm sorry, I was concerned only with the abstract class case since I somehow thought that the MappedSuperclass case was already resolved&merged.
Anyway, it partially responds to your question:
Abstract entity classes (does not apply to
@MappedSuperclass) should be left as is and they have to be part of the DiscriminatorMap so that everything works properly.@BenMorel commented on GitHub (Aug 5, 2021):
Not sure why it should be this way, though I don't really mind, as long as Doctrine does not attempt to join a non-existing class!
@olsavmic commented on GitHub (Aug 6, 2021):
@BenMorel I want to make sure we’re on the same page.
The issue with MappedSuperclass in the middle of hierarchy is still there, Beberlei confirmed it’s a bug and it needs to be fixed. I’d prepare a PR but it’s rather your contribution.
I just tested the case with joined table and:
Needs an entry in the discriminator map and a separate table exists (will be generated by schema diff) for this abstract class (which is implied by the JOINED behaviour and is valid from the DB schema point of view).
(Without
@Entityannotation) does not need an entry in the DiscriminatorMap, a table is not generated yet the class cannot contain any fields. I'd actually say it should be marked as error by the ValidatorSchema as it's very easy to forget that the@Entityannotation is missing while adding new fields.@BenMorel commented on GitHub (Oct 4, 2021):
Hi, there is still a regression in
2.9and2.10: we now have to add a fake entry for abstract entity classes in the discriminator map. This is quite an annoyance, can't this be avoided? Should I open a separate issue for this?