使用Native SQL的学说查询总是返回空数组 [英] Doctrine query using Native SQL always returning empty array
本文介绍了使用Native SQL的学说查询总是返回空数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用运行某些查询的方法创建了一个服务,我想使用主义的本机SQL,但是无论我使哪个查询始终返回一个空数组.有什么我想念的吗?
I create a service with methods that run some queries, i want to use doctrine Native SQL but no matter which query i made it always return an empty array. There is something that i'm missing?
服务MonthVacancySchedule中的方法:
Method from service MonthVacancySchedule:
public function getTotalVacanciesByUnits()
{
$rsm = new ResultSetMapping();
$sql = 'SELECT nome_procedimento FROM programacao';
$query = $this->emi->createNativeQuery($sql, $rsm);
$units = $query->getResult();
return $units;
}
我使用该服务的控制器:
The controller which i use the service:
/**
* @Route("/units", name="units")
*/
public function showTotalVacanciesByUnits( MonthVacancySchedule $mvs )
{
$units = $mvs->getTotalVacanciesByUnits();
# Always return empty array.
var_dump($units);
return $units;
}
推荐答案
这是因为您要求Doctrine提供空数组.在 rsm
对象中描述您需要的字段.例如
That's because you ask Doctrine for empty array.
Describe fields you need in rsm
object. For example
public function getTotalVacanciesByUnits()
{
$rsm = new ResultSetMapping();
$rsm->addScalarResult('nome_procedimento', 'nome_procedimento');
$sql = 'SELECT nome_procedimento FROM programacao';
$query = $this->emi->createNativeQuery($sql, $rsm);
$units = $query->getResult();
return $units;
}
这篇关于使用Native SQL的学说查询总是返回空数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文