Forward ActiveRecord::Relation#count to Enumerable#count if block given#24203
Forward ActiveRecord::Relation#count to Enumerable#count if block given#24203kaspth merged 1 commit intorails:masterfrom
Conversation
|
r? @kaspth (@rails-bot has picked a reviewer for you, use r? to override) |
a2f123b to
38dde96
Compare
d934f34 to
f8187aa
Compare
There was a problem hiding this comment.
Documentation is now outdated, we don't always count in SQL.
|
LGTM, but requires a doc update 😁 — ping me when you got 'em 😉 |
|
@kaspth Thank you for reviewing. I have added documentation for passing a block to |
There was a problem hiding this comment.
Think this would follow more logically by being moved just above.
|
Had some more comments about the docs. Remember to squash your commits 😁 |
|
Just as a reminder, we are way past the feature freeze for Rails 5. This shouldn't be merged until after 5 is branched from master. |
8cba028 to
2bc79c9
Compare
|
@kaspth I’ve fixed up the documentation as you’ve suggested and amended those changes to the previous commit. If you’d prefer, I can squash everything into a single commit. |
|
@sgrif I didn’t realize the Rails 5 feature freeze was in effect but that makes sense, considering you’ve already started shipping betas. I’m a little disappointed this feature won’t make it into Rails 5.0 but I’m excited to have it be one of the first features merged into Rails 5.1! 😄 |
|
@sferik yeah, all the way down to one commit please.
You can bet your editor, it is! 😉 |
2bc79c9 to
5c950d6
Compare
|
@kaspth Done. |
5c950d6 to
5877239
Compare
|
There we go, merged after master is 5.1 😁 |
Follow up of rails#24203. Since b644964 `ActiveRecord::Relation` includes `Enumerable` so it is enough to call `super` simply.
I came across this line of code today:
I had the idea to refactor this to use
Enumerable#count, which takes a block, instead ofEnumerable#selectfollowed byArray#size.What happened instead was this method always returned the count of all the deliveries for that order (even counting ones that are not in progress) because
ActiveRecord::Relation#countsilently discards the block argument.This is a similar situation to
ActiveRecord::Relation#find, which collides withEnumerable#find, however, in that case,superis called.