This method is deprecated or moved on the latest stable version.
The last existing version (v3.0.9) is shown here.
construct_id_map(records, primary_key=nil)
private
Given a collection of Active Record
objects, constructs a Hash which maps the
objects’ IDs to the relevant objects. Returns a 2-tuple
(id_to_record_map, ids) where id_to_record_map is the Hash, and ids is an Array of record IDs.
# File activerecord/lib/active_record/association_preload.rb, line 175
def construct_id_map(records, primary_key=nil)
id_to_record_map = {}
ids = []
records.each do |record|
primary_key ||= record.class.primary_key
ids << record[primary_key]
mapped_records = (id_to_record_map[ids.last.to_s] ||= [])
mapped_records << record
end
ids.uniq!
return id_to_record_map, ids
end