On 9 November 2010 18:46, Marnen Laibow-Koser <[email protected]> wrote: > However, here's a rule of thumb: *never* use Ruby for things like a > simple count of DB records. Let the DB do the things that it's good at. > > Doing a count of DB records on the Ruby side? I wouldn't dignify that > with the term "personal preference".
As a thought-experiment, how would you handle several counts in a row on a rapidly changing table for some form of end-user report? If I do one SQL query for a count by one set of criteria, and then do another query for a similar query, but just grouped differently, I may get different numbers because the underlying records in the table have changed. If I do the same thing in code; I do one DB query, and then use the Ruby/Rails methods to manipulate that data how I need, and I can always be assured that I am at least *always* operating on the set same records for that request. This is the kind of situation that I have a "personal preference" to do in code, not in the DB (although the DB may be better *at* it, there's a chance my numbers won't be the same which will confuse users). -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

