I want to use an inner Join for my tables auto and rent('s'). Its an 1:N relationship. If I use ->innerJoin('s', 'a')
it comes to some errors like this:
[Semantical Error] line 0, col 62 near 'sa, ChrisKfzBuchungBundle:Auto': Error: Class 's' is not defined.
$repo = $this->getDoctrine()->getRepository('ChrisKfzBuchungBundle:Rent');
$qb = $repo->createQueryBuilder('s');
$qb->from('ChrisKfzBuchungBundle:Auto', 'a')
->where('s.mieteStart >= :date_from')
->andWhere('s.mieteEnde <= :date_to')
->setParameter('date_from', $date_from)
->setParameter('date_to', $date_to);
How do I join one ore more tables with queryBuilder?
There are methods for that and also for me it just worked with a configured relation between the two entites. Here are two working examples:
left join:
$query = $repo->createQueryBuilder('s')
->leftJoin(ChrisKfzBuchungBundle:Auto', 'a', 'WITH', 's.id = a.yourJoinCOlumn')
...
inner join:
$query = $repo->createQueryBuilder('s')
->select('s, a')
->innerJoin('s.yourJoinColumn', 'a')
...
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.