开发者

Doctrine 2 native Query addFieldResult case sensitivity?

开发者 https://www.devze.com 2023-03-27 13:01 出处:网络
i\'m trying to figure out how to use Doctrin 2 nativeQuery. I\'ve created a simple staff class with the following attributes:

i'm trying to figure out how to use Doctrin 2 nativeQuery.

I've created a simple staff class with the following attributes:

id (id) userName (username) lastName (last_name) email (email)

note the camel cases. names in () are the names of the database fields. Not consisten and it's on purpose for testing.

when i try to use the native query i set up the following:

$rsm = new \Doctrine\ORM\Query\ResultSetMapping();
$rsm->addEntityResult('Entities\Staff', 's');
$rsm->addFieldResult('s', 'id', 'id');
$rsm->addFieldResult('s', 'userName', 'username');
$rsm->addFieldResult('s', 'lastName', 'last_name');
$rsm->addFieldResult('s', 'password', 'password');
$rsm->addFieldResult('s', 'email', 'email');
$sql = 'SELECT id, s.username, last_name,  password, email from staff s ' ;
$query = $this->em->createNativeQuery($sql, $rsm);
$users = $query->getResult();
\Doctrine\Common\Util\Debug::dump($users[0]);

when i run the query i dump an object using the dump facility and get:

object(stdClass)#97 (10) { ["CLASS"]=> string(14) "Entities\Staff" ["id"]=> int(1) ["userName"]=> NULL ["firstName"]=> NULL ["lastName"]=> NULL ["password"]=> string(5) "admin" ["email"]=> string(12) "abc@druid.dk" ["isAdmin"]=> NULL ["conferences"]=> array(0) { } ["roles"]=> array(0) { } }

note how id, email and password contains correct values while userName and lastName are both NULL.

Why is that?

thanx for any help. i'm a bit confused. I don't see any examples like this in the Doctrine documentation so maybe i've misund开发者_StackOverflowerstood something. most probable... :)


Your parameters are switched around. Try this:

$rsm->addFieldResult('s', 'username', 'userName');
$rsm->addFieldResult('s', 'last_name', 'lastName');
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号