Hmm, I never knew that it originally returned nil if there were no matches.
A replacement for .to_a though, if needed (although Jordan's recommendation is the best): people = Array(Person.find(blah blah)) If the argument to Array is an array, that's what gets returned. If it's anything else, that becomes a single item in an array). Cheers -- Pat e: [EMAIL PROTECTED] || m: +614 1327 3337 w: http://freelancing-gods.com || t: twitter.com/pat discworld: http://ausdwcon.org || skype: patallan On 18/08/2008, at 11:54 PM, Nolan Meyers wrote: > > At some point ActiveRecord was updated so that it now returns an empty > array for find(:all) calls that have zero results. So it seems to me > that calling ".to_a" is essentially redundant now? > > - Nolan > > On Aug 18, 2008, at 3:43 PM, Glenn Little 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 >> >>> > > > > --~--~---------~--~----~------------~-------~--~----~ SD Ruby mailing list [email protected] http://groups.google.com/group/sdruby -~----------~----~----~----~------~----~------~--~---
