mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Bug when use Featch EGER and SQLFilter #7126
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 @dbannik on GitHub (Apr 2, 2023).
Bug Report
Summary
There is entity:
Patientwith property collection
Order(orders with Fetch EGER)Orderwith property
Practice(sets SQLFilter of current Company in system)Company is system:
1,2When first entity load
Patientwith Company1is goodWhen (SQLFilter update parameter to Company
2) and load nextPatient, Orders collection load with practice1in SQL QUERY!Current behavior
Cached
Join sqlin persist entity (Patient) if useFetch EGERpropertyIf change SQLFilter parameter, cached join sql does not refreshed and used old sql join parameters!
entityManager->clear() persisted entity metadata does not removed!
How to reproduce
Entity: Company
Entity: Patient
Entity: Order
Patient -> OneToMany (Fetch EGER) -> Order
Order -> ManyToOne -> Company
SQLFilter set parameter Company
1(added toOrderfilter)Expected behavior
When switch SQLFilter parameter (Company) join sql should be refreshed with actual SQLFilters!
@derrabus commented on GitHub (Apr 3, 2023):
I'm sorry, I don't really understand this bug report. I tried to make sense of the test you've provided in your PR but that confuses me even more. Can you please elaborate again in full sentences…
@dbannik commented on GitHub (Apr 3, 2023):
@derrabus
I have an orm running in a message queue and I need to be able to switch context using SQL filters.
when changing the context of the "filter options" I want to get the correct correct answer result!
but when changing the filter parameter now the join is cached from the previous filter
@jelovac commented on GitHub (Jun 5, 2023):
@derrabus ,
I think I am experiencing the same issue as the author.
Take a look at the following piece of code:
What happens is that for some reason
$this->statement()->fetchAssociative()returns wrong result set.In my case it seems that this happens when there were already queries against database for the same entity.
When I inspect using xdebug the $this->statement object I can see that it is an instance of
\Doctrine\DBAL\Driver\PDO\Resultand navigating inside it I can see that actual\PDOStatementobject contains the SQL Filter part. However when statement is iterated over usingfetchAssociative()it includes rows which shouldn't be there.I am suspecting that there is some kind of cache involved.
@derrabus commented on GitHub (Jun 5, 2023):
Same questions for you then: https://github.com/doctrine/orm/issues/10610#issuecomment-1494241046
I need clear steps to reproduce the issue before I can help you.
@jelovac commented on GitHub (Jun 6, 2023):
I was wrong. My subquery condition in the filter was bad. And as I troubleshooted directly on the test database the generated PDO statement SQL I though that the filter was working because it was missing one row which I intended to filter. However, I forgot that I am using test environment and that records which are inserted during tests are not commited to the test DB (Doctrine Test Bundle). So the row was missing from the result set because it was never actually inserted.
So not an issue for me anymore.