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:
Order.where(some_query).each do |order|
CustomLogo.find_by client_id: order.client_id, origin_value: order.origin
end
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)
The code would then become
Order.where(some_query).includes(:custom_logo).each do |order|
order.custom_logo
end
However I did not find a way to define the proper has_one relationship for that.
Thanks