I'd say if you'd always like an array from ActiveRecord::Base#find, to use
the :all option.
--Jordan

On Mon, Aug 18, 2008 at 3:43 PM, Glenn Little <[EMAIL PROTECTED]> wrote:

>
> We have a number of places where we use the to_a method on the
> return of an ActiveRecord find call.  For instance:
>
>  people = Person.find(blah blah).to_a
>
> This way, whether one or more Person objects are returned, "people"
> is always an array of 0 or more elements.
>
> I notice now though that I'm getting warnings:
>
>  warning: default 'to_a' will be obsolete
>
> I believe this is from Ruby, and applies when an object does
> not define its own to_a method.  I believe this is only the case
> when my find() happens to return 1 element (an ActiveRecord object
> instead of an array of ActiveRecord objects), so I guess the
> ActiveRecord objects are not defining their own to_a?
>
> Is there a different "best practice" I might want to follow in the
> above case so that I always have an array as a find() result?
>
> Thanks!
>
>        -glenn
>
> >
>


-- 
Jordan A. Fowler
2621 First Ave Apt 5
San Diego, CA 92103
E-mail: [EMAIL PROTECTED]
Website: http://www.jordanfowler.com
Office Phone: (619) 618-0355
Cell Phone: (406) 546-8055

--~--~---------~--~----~------------~-------~--~----~
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby
-~----------~----~----~----~------~----~------~--~---

Reply via email to