165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
# File 'lib/global_id/locator.rb', line 165
def locate_many(gids, options = {})
ids_by_model = Hash.new { |hash, key| hash[key] = [] }
gids.each do |gid|
next unless model_id_is_valid?(gid)
ids_by_model[gid.model_class] << gid.model_id
end
records_by_model_name_and_id = {}
ids_by_model.each do |model, ids|
records = find_records(model, ids, ignore_missing: options[:ignore_missing], includes: options[:includes])
records_by_id = records.index_by do |record|
record.id.is_a?(Array) ? record.id.map(&:to_s) : record.id.to_s
end
records_by_model_name_and_id[model.name] = records_by_id
end
gids.filter_map { |gid| records_by_model_name_and_id[gid.model_name][gid.model_id] }
end
|