Module: ActiveRecord::NullRelation

Defined in:
activerecord/lib/active_record/null_relation.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#any?Boolean


35
36
37
# File 'activerecord/lib/active_record/null_relation.rb', line 35

def any?
  false
end

#averageObject


59
60
61
# File 'activerecord/lib/active_record/null_relation.rb', line 59

def average(*)
  calculate :average, nil
end

#calculate(operation, _column_name) ⇒ Object


71
72
73
74
75
76
77
78
79
# File 'activerecord/lib/active_record/null_relation.rb', line 71

def calculate(operation, _column_name)
  if [:count, :sum, :size].include? operation
    group_values.any? ? Hash.new : 0
  elsif [:average, :minimum, :maximum].include?(operation) && group_values.any?
    Hash.new
  else
    nil
  end
end

#countObject


51
52
53
# File 'activerecord/lib/active_record/null_relation.rb', line 51

def count(*)
  calculate :count, nil
end

#delete(_id_or_array) ⇒ Object


19
20
21
# File 'activerecord/lib/active_record/null_relation.rb', line 19

def delete(_id_or_array)
  0
end

#delete_all(_conditions = nil) ⇒ Object


11
12
13
# File 'activerecord/lib/active_record/null_relation.rb', line 11

def delete_all(_conditions = nil)
  0
end

#empty?Boolean


27
28
29
# File 'activerecord/lib/active_record/null_relation.rb', line 27

def empty?
  true
end

#exec_queriesObject


3
4
5
# File 'activerecord/lib/active_record/null_relation.rb', line 3

def exec_queries
  @records = [].freeze
end

#exists?(_conditions = :none) ⇒ Boolean


81
82
83
# File 'activerecord/lib/active_record/null_relation.rb', line 81

def exists?(_conditions = :none)
  false
end

#many?Boolean


43
44
45
# File 'activerecord/lib/active_record/null_relation.rb', line 43

def many?
  false
end

#maximumObject


67
68
69
# File 'activerecord/lib/active_record/null_relation.rb', line 67

def maximum(*)
  calculate :maximum, nil
end

#minimumObject


63
64
65
# File 'activerecord/lib/active_record/null_relation.rb', line 63

def minimum(*)
  calculate :minimum, nil
end

#none?Boolean


31
32
33
# File 'activerecord/lib/active_record/null_relation.rb', line 31

def none?
  true
end

#one?Boolean


39
40
41
# File 'activerecord/lib/active_record/null_relation.rb', line 39

def one?
  false
end

#or(other) ⇒ Object


85
86
87
# File 'activerecord/lib/active_record/null_relation.rb', line 85

def or(other)
  other.spawn
end

#pluck(*column_names) ⇒ Object


7
8
9
# File 'activerecord/lib/active_record/null_relation.rb', line 7

def pluck(*column_names)
  []
end

#sizeObject


23
24
25
# File 'activerecord/lib/active_record/null_relation.rb', line 23

def size
  calculate :size, nil
end

#sumObject


55
56
57
# File 'activerecord/lib/active_record/null_relation.rb', line 55

def sum(*)
  calculate :sum, nil
end

#to_sqlObject


47
48
49
# File 'activerecord/lib/active_record/null_relation.rb', line 47

def to_sql
  ""
end

#update_all(_updates) ⇒ Object


15
16
17
# File 'activerecord/lib/active_record/null_relation.rb', line 15

def update_all(_updates)
  0
end