rails/rails — pull request #8268 by carlosantoniodasilva (2012-11-19 11:26:05+00:00)
Title: Deprecate calculations with block

This is a follow up of the [discussion from the original merge commit](https://github.com/rails/rails/commit/f9cb645dfcb5cc89f59d2f8b58a019486c828c73#commitcomment-1414561), after 6 months :smile:.

The big picture is that we want to avoid people's mistakes with methods like `count ` and `sum` when called with a block, that can easily lead to code performing poorly and that could be way better written with a db query. Please check the discussion there for more background.

The idea was to raise an exception if a block is given, but since `sum` currently accepts a block, changing it to an exception doesn't sound good, so it's better to first deprecate, then changing later to an exception is that's the case.

There's an additional but related commit in this pull request, 2382e51145c4306a3fb1e85145da08b2990653ed, that removes the `sum` method from the `CollectionAssociation`, since it's already being delegated to the scope after edd94cee9af1688dd036fc58fd405adb30a5e0da, that method is never called. Please check the commit message for more info.

I wanted to get more feedback on this one before applying it, so any feedback is welcome.

/cc @adzap @jonleighton @josevalim @rafaelfranca