Class: ActiveRecord::Associations::Preloader::AlreadyLoaded

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/associations/preloader.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(klass, owners, reflection, preload_scope, associate_by_default = true) ⇒ AlreadyLoaded

Returns a new instance of AlreadyLoaded.



164
165
166
167
# File 'lib/active_record/associations/preloader.rb', line 164

def initialize(klass, owners, reflection, preload_scope, associate_by_default = true)
  @owners = owners
  @reflection = reflection
end

Instance Method Details

#preloaded_recordsObject



173
174
175
# File 'lib/active_record/associations/preloader.rb', line 173

def preloaded_records
  @preloaded_records ||= records_by_owner.flat_map(&:last)
end

#records_by_ownerObject



177
178
179
180
181
# File 'lib/active_record/associations/preloader.rb', line 177

def records_by_owner
  @records_by_owner ||= owners.each_with_object({}) do |owner, result|
    result[owner] = Array(owner.association(reflection.name).target)
  end
end

#runObject



169
170
171
# File 'lib/active_record/associations/preloader.rb', line 169

def run
  self
end