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?
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;
}
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;
}
http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/native-sql.html#scalar-results
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With