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.
- #owners_by_key ⇒ Object
- #preload(preloader) ⇒ Object
- #query_scope(ids) ⇒ 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 17 |
# 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 @owners_by_key = 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
50 51 52 |
# File 'lib/active_record/associations/preloader/association.rb', line 50 def association_key table[association_key_name] end |
#association_key_name ⇒ Object
The name of the key on the associated records
44 45 46 |
# File 'lib/active_record/associations/preloader/association.rb', line 44 def association_key_name raise NotImplementedError end |
#options ⇒ Object
71 72 73 |
# File 'lib/active_record/associations/preloader/association.rb', line 71 def reflection. end |
#owner_key_name ⇒ Object
The name of the key on the model which declares the association
55 56 57 |
# File 'lib/active_record/associations/preloader/association.rb', line 55 def owner_key_name raise NotImplementedError end |
#owners_by_key ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/active_record/associations/preloader/association.rb', line 59 def owners_by_key @owners_by_key ||= if key_conversion_required? owners.group_by do |owner| owner[owner_key_name].to_s end else owners.group_by do |owner| owner[owner_key_name] end end end |
#preload(preloader) ⇒ Object
23 24 25 |
# File 'lib/active_record/associations/preloader/association.rb', line 23 def preload(preloader) raise NotImplementedError end |
#query_scope(ids) ⇒ Object
35 36 37 |
# File 'lib/active_record/associations/preloader/association.rb', line 35 def query_scope(ids) scope.where(association_key.in(ids)) end |
#records_for(ids) ⇒ Object
31 32 33 |
# File 'lib/active_record/associations/preloader/association.rb', line 31 def records_for(ids) query_scope(ids) end |
#run(preloader) ⇒ Object
19 20 21 |
# File 'lib/active_record/associations/preloader/association.rb', line 19 def run(preloader) preload(preloader) end |
#scope ⇒ Object
27 28 29 |
# File 'lib/active_record/associations/preloader/association.rb', line 27 def scope @scope ||= build_scope end |
#table ⇒ Object
39 40 41 |
# File 'lib/active_record/associations/preloader/association.rb', line 39 def table klass.arel_table end |