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
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
this way.
Any help much appreciated!
Thanks.
--
Posted via http://www.ruby-forum.com/.
--
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.