-
-
Notifications
You must be signed in to change notification settings - Fork 506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect number of database queries when retrieving a document with class inheritance #2723
Comments
The objects retrieved using |
I understand what you're saying, and that's exactly what I'm doing in the code I posted earlier. That is, I loop through all the child classes to check if it exists in the entityMap, and if so, it returns it; something as simple as that would avoid many unnecessary database queries. Overriding the find method is an option, and I'm already doing that, but I think this behavior should be built into the library itself. |
I’ve run the test using ORM instead of ODM, and it works fine with ORM, meaning UOW handles it well even with classes that have inheritance. |
You are right @parada85, looks like ORM uses mongodb-odm/lib/Doctrine/ODM/MongoDB/UnitOfWork.php Lines 1658 to 1667 in a00f135
Let me try to find a solution for this 🙏🏻 |
Bug Report
Summary
Problem class inheritance save in entitymap
How to reproduce
I have a simple class inheritance like this:
Then I do something like this:
It seems like two database queries are made, but only one should be executed since it should be cached in the entity map. The issue seems to be that when it looks up the entity map, it does so using the repository class, but then stores it with the actual class (the child class) instead.
However, if I do this:
It works correctly, and only one query is made.
When fetching the same document twice, only one database query should be executed if the entity is already cached in the entity map, regardless of whether the parent or child class is used.
To resolve the issue, I have overridden the find method of the DocumentRepository and do the following:
but method tryGetById is marked internal :(
The text was updated successfully, but these errors were encountered: