title: Rails 4 Conversation Model JOIN Table with condition
body: <p>I have a <strong>Conversation</strong> model with</p>
  
  <pre><code>recipient_id
  sender_id
  </code></pre>
  
  <p>Fetching the current user's conversations looks like</p>
  
  <pre><code>conversations = Conversation.where("conversations.sender_id =? OR conversations.recipient_id =?",current_user.id,current_user.id)
  </code></pre>
  
  <p>Let's call <strong>other_user</strong> the user in the conversation who is not the current_user.</p>
  
  <p>Since the current user can either be the sender or the recipient, it's not possible to use a JOIN or Include on the users table to fetch the "other user" involved in the conversation. Thus, rendering the conversations creates a N+1 situation, issuing 1 query for each other user.</p>
  
  <p>Is there a way to fetch the other_user using an includes or a JOIN, with a condition basically saying:</p>
  
  <pre><code>if current_user_id == recipient_id JOIN on recipient_id
  if current_user_id == sender_id JOIN on sender_id
  </code></pre>