Class: ActiveRecord::Associations::Preloader::AlreadyLoaded
- Defined in:
- activerecord/lib/active_record/associations/preloader.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#initialize(klass, owners, reflection, preload_scope) ⇒ AlreadyLoaded
constructor
A new instance of AlreadyLoaded.
- #preloaded_records ⇒ Object
- #records_by_owner ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(klass, owners, reflection, preload_scope) ⇒ AlreadyLoaded
Returns a new instance of AlreadyLoaded.
160 161 162 163 |
# File 'activerecord/lib/active_record/associations/preloader.rb', line 160 def initialize(klass, owners, reflection, preload_scope) @owners = owners @reflection = reflection end |
Instance Method Details
#preloaded_records ⇒ Object
169 170 171 |
# File 'activerecord/lib/active_record/associations/preloader.rb', line 169 def preloaded_records @preloaded_records ||= records_by_owner.flat_map(&:last) end |
#records_by_owner ⇒ Object
173 174 175 176 177 |
# File 'activerecord/lib/active_record/associations/preloader.rb', line 173 def records_by_owner @records_by_owner ||= owners.each_with_object({}) do |owner, result| result[owner] = Array(owner.association(reflection.name).target) end end |
#run ⇒ Object
165 166 167 |
# File 'activerecord/lib/active_record/associations/preloader.rb', line 165 def run self end |