Sha256: 3658aa9ddaaad06a24e9f11df38e571123571c83ec1a14f238fb1dae548d753b

Contents?: true

Size: 1.2 KB

Versions: 32

Compression:

Stored size: 1.2 KB

Contents

module ActiveRecord
  module NullRelation # :nodoc:
    def exec_queries
      @records = [].freeze
    end

    def pluck(*column_names)
      []
    end

    def delete_all(_conditions = nil)
      0
    end

    def update_all(_updates)
      0
    end

    def delete(_id_or_array)
      0
    end

    def size
      calculate :size, nil
    end

    def empty?
      true
    end

    def none?
      true
    end

    def any?
      false
    end

    def one?
      false
    end

    def many?
      false
    end

    def to_sql
      ""
    end

    def count(*)
      calculate :count, nil
    end

    def sum(*)
      calculate :sum, nil
    end

    def average(*)
      calculate :average, nil
    end

    def minimum(*)
      calculate :minimum, nil
    end

    def maximum(*)
      calculate :maximum, nil
    end

    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

    def exists?(_conditions = :none)
      false
    end

    def or(other)
      other.spawn
    end
  end
end

Version data entries

32 entries across 32 versions & 4 rubygems

Version Path
activerecord-5.0.7.2 lib/active_record/null_relation.rb
activerecord-5.0.7.1 lib/active_record/null_relation.rb
activerecord-5.0.7 lib/active_record/null_relation.rb
activerecord-5.0.6 lib/active_record/null_relation.rb
activerecord-5.0.6.rc1 lib/active_record/null_relation.rb
activerecord-5.0.5 lib/active_record/null_relation.rb
activerecord-5.0.5.rc2 lib/active_record/null_relation.rb
activerecord-5.0.5.rc1 lib/active_record/null_relation.rb
activerecord-5.0.4 lib/active_record/null_relation.rb
activerecord-5.0.4.rc1 lib/active_record/null_relation.rb
activerecord-5.0.3 lib/active_record/null_relation.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/activerecord-5.0.2/lib/active_record/null_relation.rb
activerecord-5.0.2 lib/active_record/null_relation.rb
activerecord-5.0.2.rc1 lib/active_record/null_relation.rb
autocompl-0.2.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/null_relation.rb
autocompl-0.2.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/null_relation.rb
autocompl-0.2.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/null_relation.rb
autocompl-0.1.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/null_relation.rb
autocompl-0.1.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/null_relation.rb
autocompl-0.1.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/null_relation.rb