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:
parent
86cc141ed5
commit
a2e607e105
2 changed files with 8 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue