JOIN ON … AND conditions when eager loading association in ActiveRecord
问题 Please notice, this is not a question about adding a WHERE condition to an association but a rather advanced question about how to alter the JOIN clause when using eager_load. Lets say I have these models class Parent has_many :children have_many :grades, through: :children end class Child belongs_to :parent end class Grade belongs_to :child end So to eager load the parents I would do: Parent.eager_load(:grades) But if I wanted all the parents - but only to eager load the highest scoring like