2
votes

I want to convert this Query to the Doctrine 2 Query Builder.

SELECT st.id,
       serwis2.uwagi_dla_serwisu,
       serwis2.data_wyslania,
       serwis2.data_powrotu
FROM st left join
     (select * from serwis where serwis.data_powrotu is null) serwis2
on serwis2.st_id = st.id

In MySQL this query is exactly what I need but I don't know how I can convert it into the QueryBuilder.

Is possible to the left join over an select subquery in the QueryBuilder?

1

1 Answers

0
votes

I am a little rusty and would need to iterate over this with the actual databases, but maybe this will help get you started... something like:

$qb->select('st.id', 'serwis2.uwagi_dla_serwisu', 'serwis2.data_wyslania','serwis2.data_powrotu')
    ->from('st')
    ->addSelect('(SELECT serwis.* FROM serwis WHERE serwis.powrotu IS NULL) AS serwis2')
    ->leftJoin('st.id', 'serwis2', 'WITH', 'st.id = serwis2.st_id');

It's probably not something you can copy or paste, but a visit to the query builder reference should help.