mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Multiple level discriminator mapping does not work in combination with a self-referencing one-to-many relation. #5565
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 (Jun 7, 2017).
Originally assigned to: @Ocramius on GitHub.
Given the following structure of entities, we are experiencing fatal errors the moment we try to make use of the self-referencing relation.
The multiple level discrimination on itself works fine. We can query for the object directly or get it from a related entity. But the moment we insert data in the parent_id column in the database and try to call the ‘getParent()’ method we get the following fatal error:
PHP Fatal error: Cannot instantiate abstract class FinancialBundle\Entity\Invoice\Line\SocialSupport\AbstractProduct in ..vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php on line 872
An important detail is that we CAN use the self-referencing relation when querying for the ‘AddonMedicine’ entity. So it looks like that when we use the combination of the self-referencing relation AND the multiple level discrimination something is not interpreted right and that Doctrine is trying to instantiate the ‘middle layer’, being the AbstractProduct.
These are the mapping files in use:
AbstractLine
AbstractProduct
OutputOrientedProduct
AddonMedicine
@Ocramius commented on GitHub (Jun 7, 2017):
What's the code causing that error? Looks like a wrong discriminator value being used? What's the trace for that exception? Can this be reproduced in a test case?
@jeroenvrooij commented on GitHub (Jun 8, 2017):
Hi Ocramius, thanks for your quick reply.
$this->repository->find($id);. The repository being used the the repository of the AbstracProduct, but we've also tried using the repo from the abstractLine (top level) and the OutputOrientedProduct (the concrete leaf) and that yields the same results.Trace:
@Ocramius commented on GitHub (Jun 8, 2017):
Is there an automated test for this?
@Ocramius commented on GitHub (Jun 8, 2017):
See
971c400025/tests/Doctrine/Tests/ORM/Functionalfor examples@jeroenvrooij commented on GitHub (Jun 8, 2017):
No, there is no automated test for this. For me to make one would take me some time, which I do not have at the moment. So the best I can do for now are the repro steps I provided. Will that be an issue?
@Ocramius commented on GitHub (Jun 8, 2017):
Well, until there's a test case nobody will really look at it :-\
@jeroenvrooij commented on GitHub (Jul 18, 2017):
After some more investigation it turned out it had nothing to do with the self-referencing relation. Because of this, and some new insights, I have made a new issue: https://github.com/doctrine/doctrine2/issues/6558. Will hereby close this one.