Hi, I'm wondering if this is an arel bug or should be a new feature.
I've got a model with the following:
has_many :recommendations, :class_name => "Referral", :foreign_key => :candidate_id scope :recommended_to, lambda {|er| joins(:recommendations).where(:referrals => {:employer_representative => er})}
This works and generates the right inner join.
puts User.recommended_to(er).to_sql users" INNER JOIN "referrals" ON "referrals"."candidate_id" = "users"."id" WHERE ("referrals"."employer_representative" = '6')
But if I change joins to includes in the scope, I get: puts User.recommended_to(er).to_sql SELECT "users".* FROM "users" WHERE ("referrals"."employer_representative" = '6')
Which won't work since it needs the join.
I know that the old :include option only generated a join clause if there was also a condition which required it, and since the includes method doesn't know that it kind of makes sense. I also tried chaining the includes after the where in hopes that then include WOULD know, but it didn't make a difference.
Is there, or should there, be a way in such a case to force includes to generate the join as well as instantiating the associated records?