mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
FindOneBy not following criteria #6969
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 @AndresConpas on GitHub (Apr 29, 2022).
Bug Report
Summary
I am using FindOneBy and Doctrine returns an object that only matches one of 2 iterations of the criteria array, meaning it is behaving like an OR instead of an AND condition.
Current behavior
Returns an object that matches only ONE criteria
$em->getRepository(Test::class)->findOneBy(["testCode" => "001", "testName" => "MY TEST"]);Returning an existing object that only differs from the corrent one in TestCode:
How to reproduce
Not so sure if this will happen all the time, but this is certainly doing this for me at the moment. I have a normal DB with no weird things going on. Using a query in SQL returns the expected result, obviously in an array and not an object, but the correct result nonetheless.
Using the
findOneBy()method should be enough, in my case the BD is big, with a good ammount of rows to search on, in case this is useful info.Expected behavior
Returning the correct object:
@AndresConpas commented on GitHub (May 5, 2022):
It seems that using a composite primary key in the Entity was the solution, since both columns could have repeated values but the combination of both was indeed unique. I still do not quite understand why this affects the
findOneBy()method when I am searching for both values though.@cpxPratik commented on GitHub (Oct 20, 2023):
I am having same issue. Both
findBy()andfindOneBy()gets last one that matched only first criteria ignoring other criteria.