Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>@florian gave you the correct answer but let me try to explain it on example:</p> <p>In sql, joins are done like this:</p> <pre><code>SELECT * FROM category LEFT JOIN product ON product.category_id = category.id </code></pre> <p>(or something like this)</p> <p>Now in Doctrine, you don't need to use <code>ON</code> clause because doctrine knows that from relations annotations in your entities. So above example would be:</p> <pre><code>// CategoryRepository.php public function getCategoriesAndJoinProducts() { return $this-&gt;createQueryBuilder("o") -&gt;leftJoin("o.products", "p")-&gt;addSelect("p") -&gt;getQuery()-&gt;getResult() ; } </code></pre> <p>Both would fetch all categories and join products associated with them.</p> <p>Now comes the <code>WITH</code> clause. If you want to join only products with price bigger than 50, you would do this in SQL:</p> <pre><code>SELECT * FROM category LEFT JOIN product ON product.category_id = category.id AND product.price&gt;50 </code></pre> <p>In Doctrine:</p> <pre><code>// CategoryRepository.php public function getCategoriesAndJoinProductsWithPriceBiggerThan($price) { return $this-&gt;createQueryBuilder("o") -&gt;leftJoin("o.products", "p", "WITH", "p.price&gt;:price") -&gt;setParameter("price", price)-&gt;addSelect("p") -&gt;getQuery()-&gt;getResult() ; } </code></pre> <p>So, in reality you should never, ever use <code>ON</code> if you are using Doctrine. If you have a need for something like that, you can be almost sure that you screwed something else.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

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