Преобразовать mysql в doctrine - PullRequest
0 голосов
/ 21 июня 2020

У меня есть следующий MySQL запрос

select a.*, d.*, p.*, pow.* from appointment a
left join doctor d on d.id = a.doctor_id
left join patient p on p.id = a.patient_id
left join point_of_work pow on pow.id = a.point_of_work_id
where (doctor_id, patient_id, date) = (
   select doctor_id, patient_id,
     coalesce(
       min(case when date > curdate() then date end),
       max(case when date < curdate() then date end)
     ) date
   from appointment
   where (doctor_id, patient_id) = (a.doctor_id, a.patient_id)
)
and d.external_id = 1

И я пытаюсь преобразовать его в DQL.

Сейчас я перехожу к этой версии DQL, но, похоже, я ' что-то делаю (а может, еще :( неправильно)

$expr = $this->getEntityManager()->getExpressionBuilder();
        $queryBuilder = $this->createQueryBuilder('a')
            ->leftJoin(Doctor::class, 'd')
            ->leftJoin(Patient::class, 'p')
            ->leftJoin(PointOfWork::class, 'pow')
            ->where(
                $expr->eq('doctorId, patient_id, date',
                    $this->createQueryBuilder('a')
                        ->select(Appointment::class . ', 
                            coalesce(
                                min(case when date > curdate() then date end),
                                max(case when date < curdate() then date end)
                                ) date'
                        )
                    ->where ('(doctorId, patientId) = (a.doctorId, a.patientId)')
                )
            )
            ->andWhere('d.externalId = :externalId')
            ->setParameter('externalId', $doctorExternalId)
            ->setMaxResults($limit)
            ->setFirstResult($offset);

Какие подходы мне нужны для преобразования DQL?

...