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,
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
do something else
My ActiveRecord is very poor - created_on is a field on the Item model,
but I can't find out how to efficiently query an ActiveRecord result in
Any help much appreciated!