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

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

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(klass, owners, reflection, preload_scope) ⇒ AlreadyLoaded

Returns a new instance of AlreadyLoaded.


162
163
164
165
# File 'activerecord/lib/active_record/associations/preloader.rb', line 162

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

Instance Method Details

#preloaded_recordsObject


171
172
173
# File 'activerecord/lib/active_record/associations/preloader.rb', line 171

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

#records_by_ownerObject


175
176
177
178
179
# File 'activerecord/lib/active_record/associations/preloader.rb', line 175

def records_by_owner
  @records_by_owner ||= owners.index_with do |owner|
    Array(owner.association(reflection.name).target)
  end
end

#runObject


167
168
169
# File 'activerecord/lib/active_record/associations/preloader.rb', line 167

def run
  self
end