title: Add conditions do activerecord includes
body: <p>First I have this:</p>
  
  <p><code>has_one :guess
  scope :with_guesses, -&gt;{ includes(:guess) }</code></p>
  
  <p>Which loads all guesses (if they exists) for a 'X' model (run two queries). That's ok. works perfectly.</p>
  
  <p>But I need to add one more condition to It.</p>
  
  <p>If I do (my first thought):</p>
  
  <p><code>scope :with_guesses, -&gt;(user) { includes(:guess).where("guesses.user_id = ?", user.id) }</code></p>
  
  <p>It will also run ok, BUT in one query (join) which will exclude results that doesn't have a 'guess'.</p>
  
  <p>Any tips on how to use include with conditions but KEEPING the results that don't have a 'guess' ?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I ended up solving this by using a decorator, which I can pass the user as a context in the controller call, keeping the views clean.</p>
  
  <p>I've used the Draper gem (<a href="https://github.com/drapergem/draper" rel="nofollow">https://github.com/drapergem/draper</a>) to do this. You don't really need a gem to work with decorators in rails, but it can be helpful.</p>