Symfony2 sublevel query

I’m trying to get a list of flights from a search form. User picks a city, a number of passengers, and my query returns all available flights.

I tried this one :

public function findSearch($city, $nbpax)
{
    $qb = $this->createQueryBuilder('a');

    $qb->where('a.precisedate >= :now')
        ->setParameter('now', new DateTime())
        ->andWhere('a.available > :min')
        ->setParameter('min', $nbpax)
        ->andWhere('a.departure > :min')
        ->setParameter('min', $nbpax)
        ->andWhere('a.departure.city = :city')
        ->setParameter('city', $city)
        ->orderBy('a.precisedate', 'ASC')
    ;

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

But it seems like the a.departure.city is not recognised as a valid comparison (departure is an airport, linked to a city with a OneToMany relationship)

How can I change my query so that I can access the airport city ?


Source: mysql

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.