Yogi
Yogi

Reputation: 1

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

$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')?

Upvotes: -1

Views: 29

Answers (2)

Yogi
Yogi

Reputation: 1

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.

Upvotes: 0

malarzm
malarzm

Reputation: 2966

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.

Upvotes: 0

Related Questions