1

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 's a, 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?

3

1 Answer 1

2

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')
    ...
Sign up to request clarification or add additional context in comments.

1 Comment

[Semantical Error] line 0, col 90 near 's a WHERE s.mieteStart': Error: Class 's' is not defined. please post the complete code. where in your left join is a definded?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.