0

In Doctrine (Symfony3) I am trying to fetch minimal data from my visit record with an array-result:

public function findByNonDeparted($user)
{
    $qb = $this->getEntityManager()->createQueryBuilder();
    $qb
        ->select('v.id,v.status,v.arrivalStatus,v.personId,v.arrivalDate,v.departureDate')
        ->from('MyAccommodationBundle:Visit', 'v')
        ->leftJoin('v.accommodationPeriods','ap')
        ->leftJoin('ap.roomType','r')
        ->leftJoin('r.stayArea','s');

    return $qb->getQuery()->getArrayResult();
}

How exactly do I include "accommodation periods" in the select statement?

I tried various things:

SELECT('v.id, v.status, v.arrivalStatus, v.personId, v.arrivalDate, v.departureDate, ap')

this gives the following error:

Cannot select entity through identification variables without choosing at least one root entity alias.

adding 'v' in the select statement will solve that, but it will return all values of 'v', and not just the ones i specified in the select-statement

So I tried:

SELECT('v.id, v.status, v.arrivalStatus, v.personId, v.arrivalDate, v.departureDate, v.accommodationPeriods')

This gives the following error:

Must be a StateFieldPathExpression.

Then I tried:

SELECT('v.id, v.status, v.arrivalStatus, v.personId, v.arrivalDate, v.departureDate, IDENTITY(v.accommodationPeriods)')

Then a new error comes up:

Must be a SingleValuedAssociationField.

Wilt
  • 41,477
  • 12
  • 152
  • 203
xfscrypt
  • 16
  • 5
  • 28
  • 59
  • You will need some `->where()` clauses in your `->leftJoin()` (capitalisation important, first example has `leftjoin`), you can then also use `->select('v','ap')` to select all columns from `v` and `ap`, have a look at this example of how to `leftJoin` http://stackoverflow.com/a/15088250/648350 – haxxxton Jan 16 '17 at 06:53
  • thanks, but the lefJoin is already coming out fine and I would only need the selected columns. fixed the typo... – xfscrypt Jan 16 '17 at 08:43

0 Answers0