Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I have noticed the same thing as well. Doing joins in Doctrine 1.2 is a little bit different from mysql. To do a join, you have to take advantage of the relationships that Doctrine creates in each component in your case the job class. </p> <p>You can check the job's base class for these relationships I am talking about. In the setup method, they look like this for example for a community foreign key id in the job table: </p> <pre><code> $this-&gt;hasOne('community as Communitys', array( 'local' =&gt; 'community_id', 'foreign' =&gt; 'id')); </code></pre> <p>Back to your question, to do a join you have to reference the alias of the table where the foreign key belongs to. For example if you want to join on the community table with the alias Community:</p> <pre><code>-&gt;leftJoin('j.Community') </code></pre> <p>instead of </p> <pre><code>community c ON c.id = j.community_id </code></pre> <p>Notice that I didn't say join on id because in Doctrine 1.2 that is implied already. You can however choose to join on something else. </p> <p>Likewise if tables you have previously joined to need to be joined to other tables they have foreign keys to you have to </p> <p>1.use their alias in the current queryand 2.reference the component as stated in THEIR base class as well. </p> <p>So you said that you want to join community to states in the current query the way you should do it is</p> <pre><code>// join job and community first -&gt;from('job j') -&gt;leftJoin('j.Community c') // join community to state since they are the ones that are related -&gt;leftjoin('c.States s') </code></pre> <p>From here I hope you can see the pattern. At the end of the day if you look at it the idea of joining is still the same with raw sql, the only difference is the syntax: </p> <p>SQL syntax: </p> <pre><code>LEFT JOIN community c ON c.id = j.community_id </code></pre> <p>DQL syntax: </p> <pre><code>-&gt;leftJoin('j.Community c') </code></pre> <p>Anyway to answer your question, here is how the join should somewhat be done: </p> <pre><code>$q = Doctrine_Query::create() -&gt;select('*') -&gt;from('job j') -&gt;leftJoin('j.Community c') -&gt;leftJoin('c.State s') -&gt;leftJoin('s.Region r') -&gt;where('r.id = 1') -&gt;execute(); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload