Properly handle scoping with has_many :through. Fixes #14537.