When joining table using doctrine, why do we put primaryTable.JoiningTable when we use Join or InnerJoin method?

29 Views Asked by At
$qb->select('c')
    ->innerJoin('c.phones', 'p', 'WITH', 'p.phone = :phone')
    ->where('c.username = :username')
    ->setParameter('phone', $phone)
    ->setParameter('username', $username);

why do we use c.phones when we can just use innerJoin('phones', 'p', 'WITH', 'p.phone = :phone')?

2

There are 2 best solutions below

0
malarzm On

phones on its own may be ambiguous if more than one entity defines phones property. Using c. gives ORM exact information what user is expecting to happen.

0
Yogi On

Answering my own question: So in doctrine we need to think in terms of entities, not worry about tables. So if phones is a reference in that entity, then you just join the table by using c.phones, doctrine will then do the magic of joining tables.