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