On 16 December 2010 13:16, Michael Pavling <[email protected]> wrote:
> 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)

oh... or if you want it even simpler, just can use Enumerable.detect
to find out yes/no on whether the collection contains any values with
that date:

  all_results = Item.where(--- created in my date range ---)
  date_in_range = !!all_results.detect{|result|
result.created_at.strftime("%Y%d%m")}


or Array.select to return all the matches....
Basically, the Array and Enumerable APIs will probably have something
for you - have a read ;-)

http://ruby-doc.org/core/classes/Array.html
http://ruby-doc.org/core/classes/Enumerable.html

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