mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Useless join statements when using a discriminator map #5208
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 @sh4bang on GitHub (Aug 2, 2016).
Originally assigned to: @Ocramius on GitHub.
Hi !
I'm working in a big project in which I use a discriminatorMap to handle many entity type : Class Table Inheritance
If we have many mapped entity inside the discriminatorMap (over something like 61 in my case), it generate a MySQL error :
The problem is that Doctrine add a join statement for each known entity, even if I don't ask him any field of any sub entity.
My closure that return a QueryBuilder (for my form type), in the repository :
Using the above QueryBuilder will generate that kind of SQL :
But I don't care about test_sub1 or test_sub2 entities... It makes no sense to use it in some cases.
Here is an easy sample to reproduce :
TestSub1 entity (duplicate for TestSub2 ) :
Stack Overflow I opened : here
@sh4bang commented on GitHub (Aug 2, 2016):
Even
or
generates the unwanted JOINS.
@w3sami commented on GitHub (Aug 24, 2016):
see https://github.com/doctrine/doctrine2/issues/5980
@Ocramius commented on GitHub (Aug 24, 2016):
This is expected behavior.
The JOINS are wanted on doctrine's side. If you ask for a parent entity in a query, you may get any child entity too, regardless of whether you want it or not. From an OOP perspective, this makes sense, since any child entity is also an instance of the parent entity.
Closing as
invalid.To solve this issue on your side:
@juaiglesias commented on GitHub (May 12, 2021):
Is this still the way it's working? Then why this documentation says:
@beberlei commented on GitHub (May 12, 2021):
The doc speaks about PARTIAL queries, is that what you are doing? Partial objects are deprecated in any case.
Querying for the root type or a parent type will generally cause these joins. Do not use JTI with many entities
@juaiglesias commented on GitHub (May 12, 2021):
Yes, I am doing a partial query. So you recommend not using CTI with many entities because this left joins are inevitable even in partial queries (I know they will go deprecated after 2.8.x but I guess an alternative will be provided for them)?
In that case - if it's okay for you - I would like to update the docs (https://github.com/doctrine/orm/blob/2.8.x/docs/en/reference/inheritance-mapping.rst) because there says another thing.