mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Side effects when override findBy and findOneBy methods with query builder #6310
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 @emr on GitHub (Sep 25, 2019).
Actually, this side effect is not related to overriding
findByandfindOneBymethods, it's related to using query builder.I've overridden
findByandfindOneBymethods to adding some query hints to all myfind*()calls. But since I've done this, some side effects that I don't want to happen have occurred.One case of them that I noticed in my Symfony project:
(Simplified code flow)
And here is my overridden
findBymethod:Because of the calling
findBymethod (overridden) on the repository, doctrine updates the object with the data in the database. Therefore, the changes made on the object cannot take effect. The object reverts to its initial state. So, no insert query is going to the database when callingflushon entity manager.Support Question
Is it idiomatic to overriding default repository methods
findByandfindOneBywith implementing query builder?I don't think that's a bug. Where can I find a document related to this issue? Or is there any configuration that might be relevant?
And, what do you think I should do for my purpose?
@SenseException commented on GitHub (Sep 25, 2019):
Hi @emr, it would be helpful if you also put a code example of your overridden
findby()method into this issue. Reading and possibly reproducing the described behavior should make it easier to help.@emr commented on GitHub (Sep 26, 2019):
@SenseException I've added the code block to the issue.
@Ocramius commented on GitHub (Sep 26, 2019):
Hmm, DQL queries don't implicitly refresh
UnitOfWorkentries: are you setting anh DQL hints on that query?@emr commented on GitHub (Sep 26, 2019):
@Ocramius I've updated the code block to show explicitly all the hints I've added to the queries.
@lcobucci commented on GitHub (Oct 1, 2019):
@emr I think this is related to how
Gedmo\Translatableworks and the magic around it. Perhaps this can be avoided if you don't hydrate the entity (by usingEntityRepository#count(), for example).@emr commented on GitHub (Oct 7, 2019):
@lcobucci of course, if I don't hydrate the entity, so any entity never gonna load to the memory.