mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Abstract subclass discriminator value is null #7301
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 @plantas on GitHub (Jan 20, 2024).
Bug Report
Summary
In case we use single table inheritance we might have intermediate abstract class that is part of the discriminator map but value in that case is null.
Current behavior
SqlWalker (
1ae74b8ec5/lib/Doctrine/ORM/Query/SqlWalker.php (L479)) does not check if value is null and the following deprecation is emitted:Expected behavior
Skip null values in the map.
I believe fix can be adding a not null check:
I'am not familiar with the internals and there might be more places in the code that should be checked. If someone more experienced would like to give a suggestion, I can open a PR with the fix.
Thanks
@mpdude commented on GitHub (Jan 20, 2024):
When the class is abstract, how can an entity exist that is of this type?
@plantas commented on GitHub (Jan 20, 2024):
@mpdude it does not exist. Abstract class A (contains discriminator map definition), abstract class B extends A, class C extends B. Only class C has value in a discriminator map. It seems like class metadata returns class B in the list of subclasses and it's discriminator value is null.
@mpdude commented on GitHub (Jan 21, 2024):
Is there any particular reason why you want that class to be in the discriminator map, and use
nullas the discriminator value?@plantas commented on GitHub (Jan 21, 2024):
@mpdude abstract class A and B aren't part of the discriminator map. The only class in the map is class C.
When we iterate over subclasses of A we get B and C (https://github.com/doctrine/orm/blob/2.17.x/lib/Doctrine/ORM/Query/SqlWalker.php#L478). B should be skipped because it is not part of the discriminator map and expression
$this->em->getClassMetadata($subclassName)->discriminatorValueevaluates to null.@yard-mschwartz commented on GitHub (Jan 26, 2024):
You are describing the same problem I'm currently facing, am I right?
I'm not allowed to do this:
Because Doctrine will tell me this:
Explicitly adding the following code block to
Fielddoesn't helpWorkaround for now is to make
ChoiceFieldan entity that I just won't be using.@mpdude commented on GitHub (Feb 2, 2024):
You might want to subscribe to #11200
@mpdude commented on GitHub (Feb 2, 2024):
Please report in #11200 whether it fixes this issue
@mpdude commented on GitHub (Feb 3, 2024):
Fixed by #11200