Class: ActiveRecord::DisableJoinsAssociationRelation

Inherits:
Relation
  • Object
show all
Defined in:
lib/active_record/disable_joins_association_relation.rb

Overview

:nodoc:

Constant Summary

Constants inherited from Relation

Relation::CLAUSE_METHODS, Relation::INVALID_METHODS_FOR_DELETE_ALL, Relation::MULTI_VALUE_METHODS, Relation::SINGLE_VALUE_METHODS, Relation::VALUE_METHODS

Constants included from FinderMethods

FinderMethods::ONE_AS_ONE

Constants included from QueryMethods

QueryMethods::FROZEN_EMPTY_ARRAY, QueryMethods::FROZEN_EMPTY_HASH, QueryMethods::VALID_UNSCOPING_VALUES

Constants included from Batches

Batches::DEFAULT_ORDER, Batches::ORDER_IGNORE_MESSAGE

Instance Attribute Summary collapse

Attributes inherited from Relation

#klass, #loaded, #predicate_builder, #skip_preloading_value, #table

Instance Method Summary collapse

Methods inherited from Relation

#==, #_exec_scope, #alias_tracker, #any?, #bind_attribute, #blank?, #cache_key, #cache_key_with_version, #cache_version, #create, #create!, #create_or_find_by, #create_or_find_by!, #delete, #delete_all, #delete_by, #destroy, #destroy_all, #destroy_by, #eager_loading?, #empty?, #empty_scope?, #encode_with, #explain, #find_or_create_by, #find_or_create_by!, #find_or_initialize_by, #first_or_create, #first_or_create!, #first_or_initialize, #has_limit_or_offset?, #initialize_copy, #insert, #insert!, #insert_all, #insert_all!, #inspect, #joined_includes_values, #load_async, #many?, #new, #none?, #one?, #preload_associations, #pretty_print, #records, #reload, #reset, #scheduled?, #scope_for_create, #scoping, #size, #to_ary, #to_sql, #touch_all, #update, #update!, #update_all, #update_counters, #upsert, #upsert_all, #values, #values_for_queries, #where_values_hash

Methods included from SignedId::RelationMethods

#find_signed, #find_signed!

Methods included from TokenFor::RelationMethods

#find_by_token_for, #find_by_token_for!

Methods included from FinderMethods

#exists?, #fifth, #fifth!, #find, #find_by, #find_by!, #find_sole_by, #first!, #forty_two, #forty_two!, #fourth, #fourth!, #include?, #last, #last!, #raise_record_not_found_exception!, #second, #second!, #second_to_last, #second_to_last!, #sole, #take, #take!, #third, #third!, #third_to_last, #third_to_last!

Methods included from Calculations

#async_average, #async_count, #async_ids, #async_maximum, #async_minimum, #async_pick, #async_pluck, #async_sum, #average, #calculate, #count, #maximum, #minimum, #pick, #pluck, #sum

Methods included from SpawnMethods

#except, #merge, #merge!, #only, #spawn

Methods included from QueryMethods

#_select!, #and, #and!, #annotate, #annotate!, #arel, #construct_join_dependency, #create_with, #create_with!, #distinct, #distinct!, #eager_load, #eager_load!, #excluding, #excluding!, #extending, #extending!, #extract_associated, #from, #from!, #group, #group!, #having, #having!, #in_order_of, #includes, #includes!, #invert_where, #invert_where!, #joins, #joins!, #left_outer_joins, #left_outer_joins!, #limit!, #lock, #lock!, #none, #none!, #null_relation?, #offset, #offset!, #optimizer_hints, #optimizer_hints!, #or, #or!, #order, #order!, #preload, #preload!, #readonly, #readonly!, #references, #references!, #regroup, #regroup!, #reorder, #reorder!, #reselect, #reselect!, #reverse_order, #reverse_order!, #rewhere, #select, #skip_preloading!, #skip_query_cache!, #strict_loading, #strict_loading!, #structurally_compatible?, #uniq!, #unscope, #unscope!, #where, #where!, #with, #with!, #with_recursive, #with_recursive!

Methods included from Batches

#find_each, #find_in_batches, #in_batches

Methods included from Explain

#collecting_queries_for_explain, #exec_explain

Methods included from Delegation

delegated_classes, uncacheable_methods

Methods included from Relation::RecordFetchWarning

#exec_queries

Constructor Details

#initialize(klass, key, ids) ⇒ DisableJoinsAssociationRelation

Returns a new instance of DisableJoinsAssociationRelation.



7
8
9
10
11
# File 'lib/active_record/disable_joins_association_relation.rb', line 7

def initialize(klass, key, ids)
  @ids = ids.uniq
  @key = key
  super(klass)
end

Instance Attribute Details

#idsObject (readonly)

Returns the value of attribute ids.



5
6
7
# File 'lib/active_record/disable_joins_association_relation.rb', line 5

def ids
  @ids
end

#keyObject (readonly)

Returns the value of attribute key.



5
6
7
# File 'lib/active_record/disable_joins_association_relation.rb', line 5

def key
  @key
end

Instance Method Details

#first(limit = nil) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/active_record/disable_joins_association_relation.rb', line 17

def first(limit = nil)
  if limit
    records.limit(limit).first
  else
    records.first
  end
end

#limit(value) ⇒ Object



13
14
15
# File 'lib/active_record/disable_joins_association_relation.rb', line 13

def limit(value)
  records.take(value)
end

#loadObject



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/active_record/disable_joins_association_relation.rb', line 25

def load
  super
  records = @records

  records_by_id = records.group_by do |record|
    record[key]
  end

  records = ids.flat_map { |id| records_by_id[id] }
  records.compact!

  @records = records
end