Class: ActiveRecord::Associations::Preloader::Association::LoaderQuery
Do not use. This class is for internal use only.
Relationships & Source Files | |
Inherits: | Object |
Defined in: | activerecord/lib/active_record/associations/preloader/association.rb |
Class Method Summary
- .new(scope, association_key_name) ⇒ LoaderQuery constructor
Instance Attribute Summary
- #association_key_name readonly
- #scope readonly
Instance Method Summary
Constructor Details
.new(scope, association_key_name) ⇒ LoaderQuery
# File 'activerecord/lib/active_record/associations/preloader/association.rb', line 12
def initialize(scope, association_key_name) @scope = scope @association_key_name = association_key_name end
Instance Attribute Details
#association_key_name (readonly)
[ GitHub ]# File 'activerecord/lib/active_record/associations/preloader/association.rb', line 10
attr_reader :scope, :association_key_name
#scope (readonly)
[ GitHub ]# File 'activerecord/lib/active_record/associations/preloader/association.rb', line 10
attr_reader :scope, :association_key_name
Instance Method Details
#eql?(other) ⇒ Boolean
# File 'activerecord/lib/active_record/associations/preloader/association.rb', line 17
def eql?(other) association_key_name == other.association_key_name && scope.table_name == other.scope.table_name && scope.model.connection_specification_name == other.scope.model.connection_specification_name && scope.values_for_queries == other.scope.values_for_queries end
#hash
[ GitHub ]# File 'activerecord/lib/active_record/associations/preloader/association.rb', line 24
def hash [association_key_name, scope.model.table_name, scope.model.connection_specification_name, scope.values_for_queries].hash end
#load_records_for_keys(keys, &block)
[ GitHub ]# File 'activerecord/lib/active_record/associations/preloader/association.rb', line 41
def load_records_for_keys(keys, &block) return [] if keys.empty? if association_key_name.is_a?(Array) query_constraints = Hash.new { |hsh, key| hsh[key] = Set.new } keys.each_with_object(query_constraints) do |values_set, constraints| association_key_name.zip(values_set).each do |key_name, value| constraints[key_name] << value end end scope.where(query_constraints) else scope.where(association_key_name => keys) end.load(&block) end
#load_records_in_batch(loaders)
[ GitHub ]# File 'activerecord/lib/active_record/associations/preloader/association.rb', line 32
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)
[ GitHub ]# File 'activerecord/lib/active_record/associations/preloader/association.rb', line 28
def records_for(loaders) LoaderRecords.new(loaders, self).records end