# File lib/dm-core/associations/relationship.rb, line 294 def eager_load(source, query = nil) target_maps = Hash.new { |h,k| h[k] = [] } collection_query = query_for(source, query) # TODO: create an object that wraps this logic, and when the first # kicker is fired, then it'll load up the collection, and then # populate all the other methods collection = source.model.all(collection_query).each do |target| target_maps[target_key.get(target)] << target end Array(source).each do |source| key = target_key.typecast(source_key.get(source)) eager_load_targets(source, target_maps[key], query) end collection end