instance method
construct_id_map
Ruby on Rails 2.2.3
Since v2.2.3 Last seen in v3.0.20 PrivateSignature
construct_id_map(records, primary_key=nil)
Given a collection of ActiveRecord 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.
Parameters
-
recordsreq -
primary_keyopt = nil
Source
# File activerecord/lib/active_record/association_preload.rb, line 164
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
Defined in activerecord/lib/active_record/association_preload.rb line 164
· View on GitHub
· Improve this page
· Find usages on GitHub