Performance improvement of ids_reader method

Hello guys.

In the method [1] ids_reader at ActiveRecord::Associations::CollectionAssociation I think we can do a performance improvement when we are dealing with has_many through associations.

class User < ActiveRecord::Base
has_many :badge_items
has_many :badges, through: :badge_items
end

In the scenario above when we do something like User#badge_ids the query called is:

SELECT “badges”.id
FROM “badges”
inner join “badge_items”
ON “badges”.“id” = “badge_items”.“badge_id”
WHERE “badge_items”.“user_id” = 1

But would be great if we have this instead:

SELECT “badge_items”.“badge_id”
FROM “badge_items”
WHERE “badge_items”.“user_id” = 1

Is this in your plans already? Can I help with anything about it?

[1] https://github.com/rails/rails/blob/master/activerecord/lib/active_record/associations/collection_association.rb#L59