mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Invalid discriminator maps should be detected during schema/mapping validation #5607
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 @jeroenvrooij on GitHub (Jul 18, 2017).
Originally assigned to: @Ocramius on GitHub.
Given the following structure of entities, which are discriminated over two levels, fetching a Developer using the repository from the root entity (Person) results in exceptions.
The issue is that an Employee object is being instantiated, which fails since that class is abstract. So it seems that Doctrine is not following the tree until the leaf nodes. Fetching the Developer using the repository from it's direct parent (so the Employee) works fine.
This may, or may not, give some insights as well:
Persisting a Developer works ok, except that the order of insert queries executed are wrong (in my opinion). The Person is inserted first, followed by the Developer and the Employee is inserted last. (So: root -> leaf -> 2nd layer). This forces us to not have foreign keys on the id columns of the Employee, Staff and Developer.
Note:
I will submit some test cases which test the two scenarios of fetching using the different repositories.
Edit:
PR with the test case: https://github.com/doctrine/doctrine2/pull/6559
@Ocramius commented on GitHub (Jul 18, 2017):
Closing as
invalidas per https://github.com/doctrine/doctrine2/pull/6559#issuecomment-316231681The issue is that the schema validation tools didn't discover a duplicate inheritance definition, but that's for a separate issue to fix.
@jeroenvrooij commented on GitHub (Jul 19, 2017):
Could you please go in to a bit more detail? Because at the moment I do not understand if I made a mistake in the inheritance mapping or that multilevel discrimination is not even supported in the first place.
We also tried having the same structure of entities, but only have to inheritance mapping on the top level like you said. But that leads to different errors: during the fetching of a Developer the Employee properties would not get populated.
@Ocramius commented on GitHub (Jul 21, 2017):
You basically need to define the inheritance mapping only at the very top of the inheritance.
@jeroenvrooij commented on GitHub (Jul 24, 2017):
Yeah I get that. But like I said, that is also not a valid mapping. We tried that as well. Please check this PR with the updated test case which hopefully clears things up :). https://github.com/doctrine/doctrine2/pull/6578
@Ocramius commented on GitHub (Jul 24, 2017):
@jeroenvrooij re-opening then, thanks for clarifying with a new test case 👍
@Ocramius commented on GitHub (Aug 19, 2017):
As discussed in https://github.com/doctrine/doctrine2/pull/6578#issuecomment-321496030, this issue is a schema validator problem: some discriminator values are missing in the discriminator map.
@mstefan21 commented on GitHub (Oct 18, 2017):
HI, i have a same problem with multiple inheritance, but i had different discriminator column names. It's ok? or i must have same discriminator column name?
Our structure is same as image, but i in Image is discriminator column name "PersonType" and in Employee is discriminator column name is "EmployeeType", if i call findAll() on Person, i get only Managers and Employes and doctrine not resolve Epmployees inheritance.
@przemyslaw-leczycki-valueadd commented on GitHub (Nov 30, 2017):
Hi @Ocramius I've got related problem to this.
My entity structure is
I've got discriminators specified in Item class.
Item is an abstract class as well as Media.
If I use
$mediaRepository->find($id)everything works fineif I use
$itemRepository->find($id)none of the values from Media Entity are populated to leaf entity.As you see on attached SQL dumps in second example doctrine didn't join items_media table at all which cause all properties from Media Entity that should be in Image Entity are null or empty string.
I saw it's reproduced in PR #6578 method
testEmployeeIsPopulated().I didn't find explicitly related issue to this. Should I create new one or it's related to this issue?