[DDC-2655] Don't let getOneOrNullResult throw NoResultException
This commit is contained in:
parent
ded3d20630
commit
089006927e
@ -609,7 +609,12 @@ abstract class AbstractQuery
|
|||||||
*/
|
*/
|
||||||
public function getOneOrNullResult($hydrationMode = null)
|
public function getOneOrNullResult($hydrationMode = null)
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
$result = $this->execute(null, $hydrationMode);
|
$result = $this->execute(null, $hydrationMode);
|
||||||
|
} catch (NoResultException $e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if ($this->_hydrationMode !== self::HYDRATE_SINGLE_SCALAR && ! $result) {
|
if ($this->_hydrationMode !== self::HYDRATE_SINGLE_SCALAR && ! $result) {
|
||||||
return null;
|
return null;
|
||||||
|
23
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2655Test.php
Normal file
23
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2655Test.php
Normal file
@ -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));
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user