title: Rails includes with join on non primary keys
body: <p>I have 2 Rails models Order and CustomLogo and would like to prevent an n+1 query on some code that can be resumed to:</p>
  
  <pre><code>Order.where(some_query).each do |order|
    CustomLogo.find_by client_id: order.client_id, origin_value: order.origin
  end
  </code></pre>
  
  <p>basically what I'd like to do is define a has_one :custom_logo on Order (that would do the proper join matching the query above) and use Order.includes(:custom_logo)</p>
  
  <p>The code would then become</p>
  
  <pre><code>Order.where(some_query).includes(:custom_logo).each do |order|
    order.custom_logo
  end
  </code></pre>
  
  <p>However I did not find a way to define the proper has_one relationship for that.</p>
  
  <p>Thanks</p>