-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow blocks for count with ActiveRecord::Relation like we do with sum #4003
Conversation
… that sum allows blocks
column_name, options = nil, column_name if column_name.is_a?(Hash) | ||
calculate(:count, column_name, options) | ||
if block_given? | ||
self.to_a.count {|*block_args| yield(*block_args)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you change this to just take one argument? Normal array count only takes one arg, so I'd rather not be splatting back and forth in here.
Hi, can you just make the change to *args, and I'll apply this. Thanks. |
Just pushed an update to this branch to use Someone just fixed something so that Removed an inaccurate documentation Note about Added a |
def count(column_name = nil, options = {}) | ||
column_name, options = nil, column_name if column_name.is_a?(Hash) | ||
calculate(:count, column_name, options) | ||
# Examples for count with a block: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This (and other comments here) seem to use old :conditions => syntax? Isn't new one simply Person.where("age > 26"), etc?
@tenderlove let me know if there's anything changes needed, e.g. cleaning up the docs as @egilburg suggests |
Is this still an issue? |
It seems to have dropped off the radar. The patch hasn't been applied. |
@tenderlove Do you still want this? |
Closed by 560aa33a47719db474d09ee7a008d7a21bcabeac |
Oooops, it is not in the rails repository yet. |
@rafaelfranca It appears to be... |
@carlosantoniodasilva told me that it is not. This is a crazy behavior of Github. It is only in the @carlosantoniodasilva's fork |
o.O @github |
also added tests and documentation about sum allowing a block.
I've been burned too many times by thinking I'm working with an Array. If we can sum on ActiveRecord::Relations like we do with Arrays, why not count with a block as well?