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 ?
You could probably do a join on departure prior to the comparisons, so:
$qb->join('a.departure', 'd')
And then instead of a.departure
you'd just do d
, eg
->andWhere('d.city = :city')
The part I don't understand is the a.departure > :min
clause, what field on a departure entity are you comparing against? Or is departure a field? In which case the a.departure.city = :city
doesn't make sense.
Regardless, the DQL documentation on joins is a good source of reference.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.