1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Make NullRelation a bit more like a real relation by returning 0 for #calculate(:count)

This commit is contained in:
Ben Woosley 2013-05-10 20:45:09 +02:00
parent 86cc141ed5
commit a2e607e105
2 changed files with 8 additions and 3 deletions

View file

@ -55,8 +55,12 @@ module ActiveRecord
end
def calculate(_operation, _column_name, _options = {})
if _operation == :count
0
else
nil
end
end
def exists?(_id = false)
false

View file

@ -279,6 +279,7 @@ class RelationTest < ActiveRecord::TestCase
def test_null_relation_calculations_methods
assert_no_queries do
assert_equal 0, Developer.none.count
assert_equal 0, Developer.none.calculate(:count, nil, {})
assert_equal nil, Developer.none.calculate(:average, 'salary')
end
end