提交 f9cb645d 编写于 作者: C Carlos Antonio da Silva

Yield only one argument instead of splatting.

Add Changelog entry. Closes #4003
上级 9cc2bf69
## Rails 4.0.0 (unreleased) ##
* Allow blocks for `count` with `ActiveRecord::Relation`, to work similar as
`Array#count`:
Person.where("age > 26").count { |person| gender == 'female' }
*Chris Finne & Carlos Antonio da Silva*
* Added support to `CollectionAssociation#delete` for passing `fixnum`
or `string` values as record ids. This finds the records responding
to the `id` and executes delete on them.
......
......@@ -21,7 +21,7 @@ module Calculations
# # => queries people where "age > 26" then count the loaded results filtering by gender
def count(column_name = nil, options = {})
if block_given?
self.to_a.count { |*block_args| yield(*block_args) }
self.to_a.count { |item| yield item }
else
column_name, options = nil, column_name if column_name.is_a?(Hash)
calculate(:count, column_name, options)
......@@ -65,7 +65,7 @@ def maximum(column_name, options = {})
# # queries people where "age > 100" then perform a sum calculation with the block returns
def sum(*args)
if block_given?
self.to_a.sum(*args) { |*block_args| yield(*block_args) }
self.to_a.sum(*args) { |item| yield item }
else
calculate(:sum, *args)
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册