DDC-1355: No Result inconsistency between Repository::find and Repository::findOneBy #1702

Open
opened 2026-01-22 13:22:38 +01:00 by admin · 0 comments
Owner

Originally created by @doctrinebot on GitHub (Sep 1, 2011).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user jelte:

When no result is found by the find() method a NoResultException is throw, but when no result is found by the findOneBy() method a null value is returned.

it would be more logical that the findOneBy() would also throw a NoResultException as you expect to find one entity.

as the following code does not work.

try { 
    $entity = $repository->findOneByCode(array("id"=>1));

    // additional validation
} catch ( NoResultException $e )  {
    $entity = new SomeEntityClass();
}

while the following does

try { 
    $entity = $repository->find(1);

    // additional validation
} catch ( NoResultException $e )  {
    $entity = new SomeEntityClass();
}

Note: I used "id" as criteria to illustrate the inconsistency.

Originally created by @doctrinebot on GitHub (Sep 1, 2011). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user jelte: When no result is found by the find() method a NoResultException is throw, but when no result is found by the findOneBy() method a null value is returned. it would be more logical that the findOneBy() would also throw a NoResultException as you expect to find one entity. as the following code does not work. ``` try { $entity = $repository->findOneByCode(array("id"=>1)); // additional validation } catch ( NoResultException $e ) { $entity = new SomeEntityClass(); } ``` while the following does ``` try { $entity = $repository->find(1); // additional validation } catch ( NoResultException $e ) { $entity = new SomeEntityClass(); } ``` Note: I used "id" as criteria to illustrate the inconsistency.
admin added the Improvement label 2026-01-22 13:22:38 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1702