Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-208

AbstractQuery::getSingleResult() should throw exception if no row is found

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-ALPHA3
    • Fix Version/s: 2.0-ALPHA4
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      AbstractQuery::getSingleResult() should throw exception if no row is found.

      This is also what JPA does, it throws a NoResultException, so we should add a Doctrine\ORM\NoResultException for this.

        Activity

        Hide
        Benjamin Eberlei added a comment -

        This probably also affects EntityManager::find($class, $identifier) and EntityRepository::find($class, $identifier)

        Show
        Benjamin Eberlei added a comment - This probably also affects EntityManager::find($class, $identifier) and EntityRepository::find($class, $identifier)
        Hide
        Roman S. Borschel added a comment -

        As was discussed, find() should rather return the entity or null, if it was not found, since find() implies that you're not sure it is there.

        Contrary to that, getSingleResult() is a strong assumption about the fact that there is a result and thus no result is usually unexpected behavior. Hence in this case an exception might be the better fit.

        Show
        Roman S. Borschel added a comment - As was discussed, find() should rather return the entity or null, if it was not found, since find() implies that you're not sure it is there. Contrary to that, getSingleResult() is a strong assumption about the fact that there is a result and thus no result is usually unexpected behavior. Hence in this case an exception might be the better fit.

          People

          • Assignee:
            Roman S. Borschel
            Reporter:
            Benjamin Eberlei
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: