title: Laravel Eloquent sort by relation table column
body: <p>I tried to sort products from <code>shop_products</code> table by <code>pinned</code> column from <code>shop_products_options</code> table:</p>
  
  <pre><code>$products = Shop\Product::with(['options' =&gt; function ($query) {
  
      $query-&gt;orderBy('pinned', 'desc'); 
  
  }])-&gt;paginate(5);
  </code></pre>
  
  <p>I set relation in Shop\Product model:</p>
  
  <pre><code>public function options()
  {
      return $this-&gt;hasOne('Shop\Options');
  }
  </code></pre>
  
  <p>But products aren't sorted. I get a query that only works with <code>shop_products_options</code> table.</p>
  
  <pre><code>SELECT * FROM `shop_products_options` WHERE `shop_products_options`.`product_id` in ('8', '9', '10', '11', '12') ORDER BY `pinned` DESC
  </code></pre>
  
  <p>How to fix it?</p>