Class: ActiveRecord::Associations::Preloader::Association
- Inherits:
-
Object
- Object
- ActiveRecord::Associations::Preloader::Association
- Defined in:
- activerecord/lib/active_record/associations/preloader/association.rb
Overview
:nodoc:
Instance Attribute Summary (collapse)
-
- (Object) klass
readonly
Returns the value of attribute klass.
-
- (Object) model
readonly
Returns the value of attribute model.
-
- (Object) owners
readonly
Returns the value of attribute owners.
-
- (Object) preload_options
readonly
Returns the value of attribute preload_options.
-
- (Object) reflection
readonly
Returns the value of attribute reflection.
Instance Method Summary (collapse)
-
- (Object) association_key
This is overridden by HABTM as the condition should be on the foreign_key column in the join table.
-
- (Object) association_key_name
The name of the key on the associated records.
-
- (Association) initialize(klass, owners, reflection, preload_options)
constructor
A new instance of Association.
- - (Object) options
-
- (Object) owner_key_name
The name of the key on the model which declares the association.
-
- (Object) owners_by_key
We're converting to a string here because postgres will return the aliased association key in a habtm as a string (for whatever reason).
- - (Object) preload
- - (Object) records_for(ids)
- - (Object) run
- - (Object) scoped
- - (Object) table
Constructor Details
- (Association) initialize(klass, owners, reflection, preload_options)
A new instance of Association
7 8 9 10 11 12 13 14 15 |
# File 'activerecord/lib/active_record/associations/preloader/association.rb', line 7 def initialize(klass, owners, reflection, ) @klass = klass @owners = owners @reflection = reflection @preload_options = || {} @model = owners.first && owners.first.class @scoped = nil @owners_by_key = nil end |
Instance Attribute Details
- (Object) klass (readonly)
Returns the value of attribute klass
5 6 7 |
# File 'activerecord/lib/active_record/associations/preloader/association.rb', line 5 def klass @klass end |
- (Object) model (readonly)
Returns the value of attribute model
5 6 7 |
# File 'activerecord/lib/active_record/associations/preloader/association.rb', line 5 def model @model end |
- (Object) owners (readonly)
Returns the value of attribute owners
5 6 7 |
# File 'activerecord/lib/active_record/associations/preloader/association.rb', line 5 def owners @owners end |
- (Object) preload_options (readonly)
Returns the value of attribute preload_options
5 6 7 |
# File 'activerecord/lib/active_record/associations/preloader/association.rb', line 5 def @preload_options end |
- (Object) reflection (readonly)
Returns the value of attribute reflection
5 6 7 |
# File 'activerecord/lib/active_record/associations/preloader/association.rb', line 5 def reflection @reflection end |
Instance Method Details
- (Object) association_key
This is overridden by HABTM as the condition should be on the foreign_key column in the join table
46 47 48 |
# File 'activerecord/lib/active_record/associations/preloader/association.rb', line 46 def association_key table[association_key_name] end |
- (Object) association_key_name
The name of the key on the associated records
40 41 42 |
# File 'activerecord/lib/active_record/associations/preloader/association.rb', line 40 def association_key_name raise NotImplementedError end |
- (Object) options
64 65 66 |
# File 'activerecord/lib/active_record/associations/preloader/association.rb', line 64 def reflection. end |
- (Object) owner_key_name
The name of the key on the model which declares the association
51 52 53 |
# File 'activerecord/lib/active_record/associations/preloader/association.rb', line 51 def owner_key_name raise NotImplementedError end |
- (Object) owners_by_key
We're converting to a string here because postgres will return the aliased association key in a habtm as a string (for whatever reason)
57 58 59 60 61 62 |
# File 'activerecord/lib/active_record/associations/preloader/association.rb', line 57 def owners_by_key @owners_by_key ||= owners.group_by do |owner| key = owner[owner_key_name] key && key.to_s end end |
- (Object) preload
23 24 25 |
# File 'activerecord/lib/active_record/associations/preloader/association.rb', line 23 def preload raise NotImplementedError end |
- (Object) records_for(ids)
31 32 33 |
# File 'activerecord/lib/active_record/associations/preloader/association.rb', line 31 def records_for(ids) scoped.where(association_key.in(ids)) end |
- (Object) run
17 18 19 20 21 |
# File 'activerecord/lib/active_record/associations/preloader/association.rb', line 17 def run unless owners.first.association(reflection.name).loaded? preload end end |
- (Object) scoped
27 28 29 |
# File 'activerecord/lib/active_record/associations/preloader/association.rb', line 27 def scoped @scoped ||= build_scope end |
- (Object) table
35 36 37 |
# File 'activerecord/lib/active_record/associations/preloader/association.rb', line 35 def table klass.arel_table end |