mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Repository methods are not consistent #6109
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 @arnaud-lb on GitHub (Nov 20, 2018).
Bug Report
Summary
Repository methods return inconsistent results when persisted entities are not flushed yet.
Current behavior
After calling
persist()on a new entity,find()is able to return the entity correctly. However, methods such asfindBy()ormatching()will ignore new entities.How to reproduce
I've added a test case here: https://github.com/doctrine/doctrine2/compare/2.6...arnaud-lb:inconsistent-repository
Expected behavior
findBy(),matching(), and other methods should behave consistently withfind().This does not seems to be completely unreasonable to implement, since
ArrayCollectionhas an in-memory implementation ofmatching().@arnaud-lb commented on GitHub (Nov 20, 2018):
I believe that, in an application that uses repositories, everything should be expected to work exactly the same way before and after durable persistence occurred (
flush()).@beberlei commented on GitHub (Dec 6, 2020):
This is actually not true,
EntitManager#find()only returns the entity when it has a "pre persist id generator", which makes sense since we can the put it into the identity map from where it is returned.The documentation could be better here explaning this in "working with objects".
@SenseException commented on GitHub (Dec 6, 2020):
Any suggestions how to formulate this behaviour?
@beberlei commented on GitHub (Dec 6, 2020):
I think a section about the identity map (it seems not to exist?) would explain when are entities added to or, in which cases it prevents a query, find(), and when it does not prevent tje query, but that it still looks in the map with the id returned from databse row