Symfony2错误:无法将类Doctrine \ ORM \ EntityManager的对象转换为字符串 [英] Symfony2 Error: Object of class Doctrine\ORM\EntityManager could not be converted to string
本文介绍了Symfony2错误:无法将类Doctrine \ ORM \ EntityManager的对象转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有2个不相关的实体:外部和内部.我需要从实体中联合选择所有结果.我正在使用ResultSetMapping和Native SQL来做到这一点:
I have 2 non related entities: External and Internal. I need to union select all results from entities. I am using ResultSetMapping and Native SQL to do this:
$em = $this->getDoctrine()
->getManager()->getConnection();
$rsm = new \Doctrine\ORM\Query\ResultSetMapping();
$rsm->addEntityResult('ExternalBundle:External', 'e');
$rsm->addFieldResult('e', 'id', 'id');
$rsm->addFieldResult('e', 'status', 'status');
$rsm->addFieldResult('e', 'name', 'name');
$rsm->addEntityResult('InternalBundle:Internal', 'i');
$rsm->addFieldResult('i', 'id', 'id');
$rsm->addFieldResult('i', 'status', 'status');
$rsm->addFieldResult('i', 'name', 'name');
$sql = "SELECT e.*
FROM external_print e
UNION
SELECT i.*
FROM internal_print i";
$objects = $this->$em->createNativeQuery($sql, $rsm)->getResult();
我一直收到此错误:可捕获的致命错误:Doctrine \ ORM \ EntityManager类的对象无法转换为字符串.
I keep getting this error: Catchable Fatal Error: Object of class Doctrine\ORM\EntityManager could not be converted to string.
需要解决什么?
推荐答案
您遇到了代码错误,而不是
You have a code error instead of
$ objects = $ this-> $ em-> createNativeQuery($ sql,$ rsm)-> getResult();
仅使用
$ objects = $ em-> createNativeQuery($ sql,$ rsm)-> getResult();
这篇关于Symfony2错误:无法将类Doctrine \ ORM \ EntityManager的对象转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文