Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #780 from terite/DDC-2655

[DDC-2655] Don't let getOneOrNullResult throw NoResultException
  • Loading branch information...
commit bb63058410a2099d571d1f9e10a8913f686d309e 2 parents be81b46 + 0890069
@guilhermeblanco guilhermeblanco authored
View
7 lib/Doctrine/ORM/AbstractQuery.php
@@ -609,7 +609,12 @@ public function getScalarResult()
*/
public function getOneOrNullResult($hydrationMode = null)
{
- $result = $this->execute(null, $hydrationMode);
+ try {
+ $result = $this->execute(null, $hydrationMode);
+ } catch (NoResultException $e) {
+ return null;
+ }
+
if ($this->_hydrationMode !== self::HYDRATE_SINGLE_SCALAR && ! $result) {
return null;
View
23 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2655Test.php
@@ -0,0 +1,23 @@
+<?php
+
+namespace Doctrine\Tests\ORM\Functional\Ticket;
+
+use Doctrine\ORM\Query;
+
+/**
+ * @group DDC-2655
+ */
+class DDC2655Test extends \Doctrine\Tests\OrmFunctionalTestCase
+{
+ public function setUp()
+ {
+ $this->useModelSet('cms');
+ parent::setUp();
+ }
+
+ public function testSingleScalarOneOrNullResult()
+ {
+ $query = $this->_em->createQuery("SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.username = 'happy_doctrine_user'");
+ $this->assertNull($query->getOneOrNullResult(Query::HYDRATE_SINGLE_SCALAR));
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.