14

What is the difference between JOIN ON and JOIN WITH in Doctrine2?

I couldn't find any relevant info in the manual.

Trent
  • 5,785
  • 6
  • 32
  • 43

1 Answers1

18

ON replaces the original join condition,
WITH adds a condition to it.


Example:

[Album] ---OneToMany---> [Track]
  1. 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
    
  2. 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
    
Peyman Mohamadpour
  • 17,954
  • 24
  • 89
  • 100
theredled
  • 998
  • 9
  • 20
  • 1
    Thanks for your answer, but I don't really get your point, can you provide me an example? – Trent Nov 06 '12 at 11:52
  • 1
    Yes, let's say you have an Album table linked with a Track table (one to many)... In DQL, if you do `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 ! – theredled Nov 06 '12 at 12:02