I have two identical Symfony 2.8 projects. The only difference in these two projects is that one is running Doctrine ORM version v2.4.8
and the other is running v2.5.5
The problem
I have this following piece of code in both Symfony projects.
$rsm = new ResultSetMapping();
$rsm->addEntityResult('EntityBundle:New', 'u');
$rsm->addFieldResult('u', 'newPK', 'newPK');
$rsm->addFieldResult('u', 'msg', 'msg');
$query = $em->createNativeQuery('StoredProcedureName @a= :a, @b= :b, @c= :c', $rsm);
$query->setParameter('a', 'a');
$query->setParameter('b', 'b');
$query->setParameter('c', 'c');
$result = $query->getArrayResult();
var_dump($result);
My Entity looks like this:
use Doctrine\ORM\Mapping as ORM;
/**
* New
*
* @ORM\Table(name="dbo.New")
* @ORM\Entity()
*/
class New
{
/**
* @var string
*
* @ORM\Column(name="newPK", type="string", length=255, unique=false)
*/
private $newPK;
/**
* @var string
*
* @ORM\Column(name="msg", type="string", length=255, unique=false)
*/
private $msg;
/**
* @return string
*/
public function getNewPK()
{
return $this->newPK;
}
/**
* @param string $newPK
*/
public function setNewPK($newPK)
{
$this->newPK = $newPK;
}
/**
* @return string
*/
public function getMsg()
{
return $this->msg;
}
/**
* @param string $msg
*/
public function setMsg($msg)
{
$this->msg = $msg;
}
}
In my StoredProcedure all I have is this:
CREATE PROCEDURE [dbo].[StoredProcedureName]
AS
SELECT null as newPK, 'aaa' As msg
GO
This code works perfectly fine on version v2.4.8
returning me null value perfectly. However this doesn't work on v2.5.5
. All it returns is an array with NULL inside it and not the newPK
AND msg
value. If I remove the null and replace it with an empty string or anything else for that matter, it works. But for some god forsaken reason, it does not like the NULL
value. All I want is to check if null is returned or not but I can't seem to check without doctrine returning me proper values.
Is there anything that changed between these versions that I am not aware of? What do I need to do in order to read NULL
values from a native query?