Здравствуйте, я хотел бы преобразовать этот запрос в DQL или в pointagerepository, у меня есть тест в нативном запросе, но return это [] пустой массив
это запрос, который я хотел бы преобразовать
select m.mon, sum(p.hours)
from (select 'Jan' as mon, 1 as mm union all
select 'Feb' as mon, 2 as mm union all
select 'March' as mon, 3 as mm union all
select 'Apr' as mon, 4 as mm union all
select 'May' as mon, 5 as mm union all
select 'June' as mon, 6 as mm union all
select 'July' as mon, 7 as mm union all
select 'Aug' as mon, 8 as mm union all
select 'Sep' as mon, 9 as mm union all
select 'Oct' as mon, 10 as mm union all
select 'Nov' as mon, 11 as mm union all
select 'Dec' as mon, 12 as mm
) m left join
pointage p
on p.date_point >= '2020/01/01' and '2021/01/01' and
p.user_id = ? and
month(p.date_point) = m.mm
group by m.mon
order by min(m.mm)
И пользователь установил Dynami c так же, как и хранилище.
Я не имею ни малейшего представления, чтобы преобразовать его, потому что это подзапрос и соединение слева на моем объекте pointage
результаты выглядят как at:
//PointageRepository
public function findRecapTotalByUser($user)
{
return $this->createQueryBuilder('p')
->select('m.mon','SUM(p.hours)')
->from("(select 'Jan' as mon, 1 as mm union all
select 'Feb' as mon, 2 as mm union all
select 'March' as mon, 3 as mm union all
select 'Apr' as mon, 4 as mm union all
select 'May' as mon, 5 as mm union all
select 'June' as mon, 6 as mm union all
select 'July' as mon, 7 as mm union all
select 'Aug' as mon, 8 as mm union all
select 'Sep' as mon, 9 as mm union all
select 'Oct' as mon, 10 as mm union all
select 'Nov' as mon, 11 as mm union all
select 'Dec' as mon, 12 as mm
)", 'm')
->andWhere('p.user = :user') //with date point but is on the left join ...
->setParameter('user', $user)
->getQuery()
->getResult();
}
Собственная попытка запроса
$rm = new ResultSetMapping();
$rm->addEntityResult(Pointage::class, 'p')
->addFieldResult('p','hours', 'hours');
$user = $this->getUser()->getId();
$sql = $manager->createNativeQuery("
SELECT m.mon, SUM(p.hours) FROM (
SELECT 'Jan' as mon, 1 as mm union all
SELECT 'Feb' as mon, 2 as mm union all
SELECT 'March' as mon, 3 as mm union all
SELECT 'Apr' as mon, 4 as mm union all
SELECT 'May' as mon, 5 as mm union all
SELECT 'June' as mon, 6 as mm union all
SELECT 'July' as mon, 7 as mm union all
SELECT 'Aug' as mon, 8 as mm union all
SELECT 'Sep' as mon, 9 as mm union all
SELECT 'Oct' as mon, 10 as mm union all
SELECT 'Nov' as mon, 11 as mm union all
SELECT 'Dec' as mon, 12 as mm
) m left join
pointage p on p.date_point >= '2020-01-01' and '2021-01-01' and
p.user_id = 1 and
month(p.date_point) = m.mm
group by m.mon
order by min(m.mm)
", $rm)
И подзапрос не разрешен.