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 Attribute Summary collapse
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#owners ⇒ Object
readonly
Returns the value of attribute owners.
-
#preload_scope ⇒ Object
readonly
Returns the value of attribute preload_scope.
-
#preloaded_records ⇒ Object
readonly
Returns the value of attribute preloaded_records.
-
#reflection ⇒ Object
readonly
Returns the value of attribute reflection.
Instance Method Summary collapse
-
#association_key ⇒ Object
This is overridden by HABTM as the condition should be on the foreign_key column in the join table.
-
#association_key_name ⇒ Object
The name of the key on the associated records.
-
#initialize(klass, owners, reflection, preload_scope) ⇒ Association
constructor
A new instance of Association.
- #options ⇒ Object
-
#owner_key_name ⇒ Object
The name of the key on the model which declares the association.
- #preload(preloader) ⇒ Object
- #records_for(ids) ⇒ Object
- #run(preloader) ⇒ Object
- #scope ⇒ Object
- #table ⇒ Object
Constructor Details
#initialize(klass, owners, reflection, preload_scope) ⇒ Association
Returns a new instance of Association.
8 9 10 11 12 13 14 15 16 |
# File 'lib/active_record/associations/preloader/association.rb', line 8 def initialize(klass, owners, reflection, preload_scope) @klass = klass @owners = owners @reflection = reflection @preload_scope = preload_scope @model = owners.first && owners.first.class @scope = nil @preloaded_records = [] end |
Instance Attribute Details
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
5 6 7 |
# File 'lib/active_record/associations/preloader/association.rb', line 5 def klass @klass end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
5 6 7 |
# File 'lib/active_record/associations/preloader/association.rb', line 5 def model @model end |
#owners ⇒ Object (readonly)
Returns the value of attribute owners.
5 6 7 |
# File 'lib/active_record/associations/preloader/association.rb', line 5 def owners @owners end |
#preload_scope ⇒ Object (readonly)
Returns the value of attribute preload_scope.
5 6 7 |
# File 'lib/active_record/associations/preloader/association.rb', line 5 def preload_scope @preload_scope end |
#preloaded_records ⇒ Object (readonly)
Returns the value of attribute preloaded_records.
6 7 8 |
# File 'lib/active_record/associations/preloader/association.rb', line 6 def preloaded_records @preloaded_records end |
#reflection ⇒ Object (readonly)
Returns the value of attribute reflection.
5 6 7 |
# File 'lib/active_record/associations/preloader/association.rb', line 5 def reflection @reflection end |
Instance Method Details
#association_key ⇒ Object
This is overridden by HABTM as the condition should be on the foreign_key column in the join table
45 46 47 |
# File 'lib/active_record/associations/preloader/association.rb', line 45 def association_key klass.arel_attribute(association_key_name, table) end |
#association_key_name ⇒ Object
The name of the key on the associated records
39 40 41 |
# File 'lib/active_record/associations/preloader/association.rb', line 39 def association_key_name raise NotImplementedError end |
#options ⇒ Object
54 55 56 |
# File 'lib/active_record/associations/preloader/association.rb', line 54 def reflection. end |
#owner_key_name ⇒ Object
The name of the key on the model which declares the association
50 51 52 |
# File 'lib/active_record/associations/preloader/association.rb', line 50 def owner_key_name raise NotImplementedError end |
#preload(preloader) ⇒ Object
22 23 24 |
# File 'lib/active_record/associations/preloader/association.rb', line 22 def preload(preloader) raise NotImplementedError end |
#records_for(ids) ⇒ Object
30 31 32 |
# File 'lib/active_record/associations/preloader/association.rb', line 30 def records_for(ids) scope.where(association_key_name => ids) end |
#run(preloader) ⇒ Object
18 19 20 |
# File 'lib/active_record/associations/preloader/association.rb', line 18 def run(preloader) preload(preloader) end |
#scope ⇒ Object
26 27 28 |
# File 'lib/active_record/associations/preloader/association.rb', line 26 def scope @scope ||= build_scope end |
#table ⇒ Object
34 35 36 |
# File 'lib/active_record/associations/preloader/association.rb', line 34 def table klass.arel_table end |