Class: ActiveRecord::Associations::Preloader::AlreadyLoaded
- Inherits:
-
Object
- Object
- ActiveRecord::Associations::Preloader::AlreadyLoaded
- Defined in:
- lib/active_record/associations/preloader.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#initialize(klass, owners, reflection, preload_scope, associate_by_default = true) ⇒ AlreadyLoaded
constructor
A new instance of AlreadyLoaded.
- #preloaded_records ⇒ Object
- #records_by_owner ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(klass, owners, reflection, preload_scope, associate_by_default = true) ⇒ AlreadyLoaded
Returns a new instance of AlreadyLoaded.
166 167 168 169 |
# File 'lib/active_record/associations/preloader.rb', line 166 def initialize(klass, owners, reflection, preload_scope, associate_by_default = true) @owners = owners @reflection = reflection end |
Instance Method Details
#preloaded_records ⇒ Object
175 176 177 |
# File 'lib/active_record/associations/preloader.rb', line 175 def preloaded_records @preloaded_records ||= records_by_owner.flat_map(&:last) end |
#records_by_owner ⇒ Object
179 180 181 182 183 |
# File 'lib/active_record/associations/preloader.rb', line 179 def records_by_owner @records_by_owner ||= owners.index_with do |owner| Array(owner.association(reflection.name).target) end end |
#run ⇒ Object
171 172 173 |
# File 'lib/active_record/associations/preloader.rb', line 171 def run self end |