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

You could use Enumerable::group_by to collect-up your records by date,
and see if the resultant collection includes the date in question (and
if not, add it if you need to)

  all_results = Item.where(--- created in my date range ---)
  grouped_all_results = all_results.group_by{|result|
result.created_at.strftime("%Y%d%m")}
  if grouped_all_results.include?(current_time.strftime("%Y%d%m"))
    ... do something
  else
     do something else
  end

You might make your group_by date and your lookup date by some other
method (like "date_value.to_s" or something), but as long as they end
up in the right format, it should work...

-- 
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.

Reply via email to