On 16 December 2010 11:46, Peter Laurens <[email protected]> wrote: > Hi, > > I am doing an ActiveRecord find against the database, bringing back a > number of objects that have a created_on date between two dates. > > After this fetch, I want to check if the result contains an object with > a specific date (actually I want to iterate through all days in a range, > and if the result contains a record, I want to get that record out of > the result array and interrogate it). > > I know how to do this by doing a new ActiveRecord find for each date in > my iteration range, but I don't want to do that as the overhead of so > many calls is too high. ] > > So I need to keep my one hit on the database, but then query the result, > something like: > > all_results = Item.where(--- created in my date range ---) > (start_date..end_date).each do |current_date| > if all_results.contains(:created_on => current_date) > ... do something > else > do something else > end > end
I don't understand, why not just use start_date and end_date as the range for your Item.where( ) call, then all the items returned will have been created in that range, do you can iterate through them all and do your '...do something' action Colin -- 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.

