Class: ActiveRecord::Associations::Preloader::Association::LoaderQuery
- Defined in:
- activerecord/lib/active_record/associations/preloader/association.rb
Instance Attribute Summary collapse
-
#association_key_name ⇒ Object
readonly
Returns the value of attribute association_key_name.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Instance Method Summary collapse
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(scope, association_key_name) ⇒ LoaderQuery
constructor
A new instance of LoaderQuery.
- #load_records_for_keys(keys, &block) ⇒ Object
- #load_records_in_batch(loaders) ⇒ Object
- #records_for(loaders) ⇒ Object
Constructor Details
#initialize(scope, association_key_name) ⇒ LoaderQuery
Returns a new instance of LoaderQuery.
10 11 12 13 |
# File 'activerecord/lib/active_record/associations/preloader/association.rb', line 10 def initialize(scope, association_key_name) @scope = scope @association_key_name = association_key_name end |
Instance Attribute Details
#association_key_name ⇒ Object (readonly)
Returns the value of attribute association_key_name
8 9 10 |
# File 'activerecord/lib/active_record/associations/preloader/association.rb', line 8 def association_key_name @association_key_name end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope
8 9 10 |
# File 'activerecord/lib/active_record/associations/preloader/association.rb', line 8 def scope @scope end |
Instance Method Details
#eql?(other) ⇒ Boolean
15 16 17 18 19 |
# File 'activerecord/lib/active_record/associations/preloader/association.rb', line 15 def eql?(other) association_key_name == other.association_key_name && scope.table_name == other.scope.table_name && scope.values_for_queries == other.scope.values_for_queries end |
#hash ⇒ Object
21 22 23 |
# File 'activerecord/lib/active_record/associations/preloader/association.rb', line 21 def hash [association_key_name, scope.table_name, scope.values_for_queries].hash end |
#load_records_for_keys(keys, &block) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'activerecord/lib/active_record/associations/preloader/association.rb', line 38 def load_records_for_keys(keys, &block) if association_key_name.is_a?(Array) or_scope = keys.map { |values_set| scope.klass.where(association_key_name.zip(values_set).to_h) }.inject(&:or) scope.merge(or_scope) else scope.where(association_key_name => keys) end.load(&block) end |
#load_records_in_batch(loaders) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'activerecord/lib/active_record/associations/preloader/association.rb', line 29 def load_records_in_batch(loaders) raw_records = records_for(loaders) loaders.each do |loader| loader.load_records(raw_records) loader.run end end |
#records_for(loaders) ⇒ Object
25 26 27 |
# File 'activerecord/lib/active_record/associations/preloader/association.rb', line 25 def records_for(loaders) LoaderRecords.new(loaders, self).records end |