What is the difference between JOIN ON and JOIN WITH in Doctrine2?
I couldn't find any relevant info in the manual.
What is the difference between JOIN ON and JOIN WITH in Doctrine2?
I couldn't find any relevant info in the manual.
ON
replaces the original join condition,
WITH
adds a condition to it.
Example:
[Album] ---OneToMany---> [Track]
Case One
DQL
FROM Album a LEFT JOIN a.Track t WITH t.status = 1
Will translate in SQL
FROM Album a LEFT JOIN Track t ON t.album_id = a.id AND t.status = 1
Case Two
DQL
FROM Album a LEFT JOIN a.Track t ON t.status = 1
Will translate in SQL
FROM Album a LEFT JOIN Track t ON t.status = 1
FROM Album a LEFT JOIN a.Track t WITH t.status = 1
, it's the equivalent of SQL FROM Album a LEFT JOIN Track t ON t.album_id = a.id AND t.status = 1
But if you do FROM Album a LEFT JOIN a.Track t ON t.status = 1
, it will be the equivalent of SQL FROM Album a LEFT JOIN Track t ON t.status = 1
, thus replacing the relation condition (t.album_id = a.id
). Hope I'm clear ! –
Pomegranate Join::ON
to set your own join conditions for this query and you use Join::WITH
to use the conditions set in the entity model as starting point and merely add additional clauses. And, at least for me, Join::ON
refuses to work in Symfony no matter what. –
Niple © 2022 - 2024 — McMap. All rights reserved.