mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Not possible to execute a WHERE condition from a parent entity with discriminators (with InheritanceType JOINED and DiscriminatorMap and DiscriminatorColumn) #5487
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 @josedacosta on GitHub (Mar 29, 2017).
Originally assigned to: @Ocramius on GitHub.
Hello,
Not possible to execute a WHERE condition from a parent entity with discriminators (with InheritanceType JOINED and DiscriminatorMap and DiscriminatorColumn)
It seems that the persist (and the cascade persist) works:
Https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Persisters/Entity/SingleTablePersister.php#L60
Https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php#L429
The logic of "parent.children.column = 12" should be the same in the WHERE condition
And well understood a WHERE on a column of a LEFT JOIN and is always possible in MySQL, there is no reason that it is not in Doctrine ...
Manual addition of the WHERE in the MySQL query (just to test):
This works manually in MySQL:
"SELECT a0_.id AS id_0, a0_.name AS name_1, f1_.fin_size AS fin_size_2, d2_.tail_size AS tail_size_3, d2_.ears_size AS ears_size_4, a0_.discriminator AS discriminator_5 FROM animal a0_ LEFT JOIN fish f1_ ON a0_.id = f1_.id LEFT JOIN dog d2_ ON a0_.id = d2_.id WHERE d2_.tail_size = 12"
Here is an example code:
Yes .. it is possible to filter that the entity child:
$queryBuilder->where('a INSTANCE OF CoreBundle\Entity\Dog');
Which will add:
... WHERE a0_.discriminator IN ('dog')
It is still not possible to make a WHERE
@Ocramius commented on GitHub (Mar 30, 2017):
From a type perspective,
Animal.tailSizedoes not exist, whileDog.tailSizedoes.DQL is not SQL, as DQL is statically checked. Support for this feature won't be added unless we add cast support in DQL.
Closing as
invalid@josedacosta commented on GitHub (Mar 30, 2017):
It's no matter what! I understand better why not many people use the doctrine of inheritance: in fact, it is useless! Apart from doing a SELECT without WHERE. I do not see the value of inheritance if it's for not having access to the child's data filtering.
Thanks anyway :/
@Ocramius commented on GitHub (Mar 30, 2017):
@josedacosta it is still useful if you select a single child in the inheritance.
@josedacosta commented on GitHub (Mar 30, 2017):
yes I grant you, INSTANCE OF, has already helped me more than once
$queryBuilder->where('a INSTANCE OF CoreBundle\Entity\Dog');
thanks
@Ocramius commented on GitHub (Mar 30, 2017):
No it needs to be the correct inheritance level in the
FROMclause.On 30 Mar 2017 1:41 p.m., "José DA COSTA" notifications@github.com wrote:
@patie commented on GitHub (Apr 20, 2017):
i understand this not fit with doctrine idea, but its really missing feature
@Ocramius commented on GitHub (Apr 20, 2017):
It's fully available in SQL ;-)
@renanBritz commented on GitHub (Aug 29, 2018):
Hello @Ocramius!
Would that SQL be tightly coupled with MySQL for example?
If the parent class metadata also held the field mappings and association mappings of its child classes, would dql be able to "validate" the queries?
Best Regards!