File tree Expand file tree Collapse file tree 2 files changed +9
-2
lines changed
lib/active_record/relation Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Original file line number Diff line number Diff line change 1
1
## Rails 4.0.0 (unreleased) ##
2
2
3
+ * Allow blocks for ` count ` with ` ActiveRecord::Relation ` , to work similar as
4
+ ` Array#count ` :
5
+
6
+ Person.where("age > 26").count { |person| gender == 'female' }
7
+
8
+ * Chris Finne & Carlos Antonio da Silva*
9
+
3
10
* Added support to ` CollectionAssociation#delete ` for passing ` fixnum `
4
11
or ` string ` values as record ids. This finds the records responding
5
12
to the ` id ` and executes delete on them.
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ module Calculations
21
21
# # => queries people where "age > 26" then count the loaded results filtering by gender
22
22
def count ( column_name = nil , options = { } )
23
23
if block_given?
24
- self . to_a . count { |* block_args | yield ( * block_args ) }
24
+ self . to_a . count { |item | yield item }
25
25
else
26
26
column_name , options = nil , column_name if column_name . is_a? ( Hash )
27
27
calculate ( :count , column_name , options )
@@ -65,7 +65,7 @@ def maximum(column_name, options = {})
65
65
# # queries people where "age > 100" then perform a sum calculation with the block returns
66
66
def sum ( *args )
67
67
if block_given?
68
- self . to_a . sum ( *args ) { |* block_args | yield ( * block_args ) }
68
+ self . to_a . sum ( *args ) { |item | yield item }
69
69
else
70
70
calculate ( :sum , *args )
71
71
end
You can’t perform that action at this time.
0 commit comments