Class: ActiveRecord::Associations::Preloader::Association
- Inherits:
-
Object
- Object
- ActiveRecord::Associations::Preloader::Association
- Defined in:
- lib/active_record/associations/preloader/association.rb
Overview
:nodoc:
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(klass, owners, reflection, preload_scope, associate_by_default = true) ⇒ Association
constructor
A new instance of Association.
- #preloaded_records ⇒ Object
- #records_by_owner ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(klass, owners, reflection, preload_scope, associate_by_default = true) ⇒ Association
Returns a new instance of Association.
7 8 9 10 11 12 13 14 |
# File 'lib/active_record/associations/preloader/association.rb', line 7 def initialize(klass, owners, reflection, preload_scope, associate_by_default = true) @klass = klass @owners = owners.uniq(&:__id__) @reflection = reflection @preload_scope = preload_scope @associate = associate_by_default || !preload_scope || preload_scope.empty_scope? @model = owners.first && owners.first.class end |
Instance Method Details
#preloaded_records ⇒ Object
32 33 34 35 36 |
# File 'lib/active_record/associations/preloader/association.rb', line 32 def preloaded_records load_records unless defined?(@preloaded_records) @preloaded_records end |
#records_by_owner ⇒ Object
26 27 28 29 30 |
# File 'lib/active_record/associations/preloader/association.rb', line 26 def records_by_owner load_records unless defined?(@records_by_owner) @records_by_owner end |
#run ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/active_record/associations/preloader/association.rb', line 16 def run records = records_by_owner owners.each do |owner| associate_records_to_owner(owner, records[owner] || []) end if @associate self end |