Mike Kogan
2006-Jul-20 16:54 UTC
[Rails] Does Find also tell you a count of the array size?
When I use @persons = Find(:all) (for example) and I get back an array of persons, is there an easy way to tell how many rows the find returned? I have been using Persons.count(:all) but you would think Find knows how many it returned -- is the count/array size stored somewhere in the ret array? -- Posted via http://www.ruby-forum.com/.
Greg Donald
2006-Jul-20 17:03 UTC
[Rails] Does Find also tell you a count of the array size?
On 7/20/06, Mike Kogan <mike@kogan.org> wrote:> When I use @persons = Find(:all) (for example) and I get back an array > of persons, is there an easy way to tell how many rows the find > returned? > > I have been using Persons.count(:all) but you would think Find knows how > many it returned -- is the count/array size stored somewhere in the ret > array?You can inspect your @persons array with irb. @persons.methods.sort for example will show you that you have a method called ''count''. -- Greg Donald http://destiney.com/
Josh Knowles
2006-Jul-20 17:22 UTC
[Rails] Does Find also tell you a count of the array size?
On 7/20/06, Mike Kogan <mike@kogan.org> wrote:> > When I use @persons = Find(:all) (for example) and I get back an array > of persons, is there an easy way to tell how many rows the find > returned? > > I have been using Persons.count(:all) but you would think Find knows how > many it returned -- is the count/array size stored somewhere in the ret > array?As you stated the result is stored in an array, based on this you can use the methods of the array to find out the number of entries: @people = Person.find :all @people_count = @people.size References: http://www.ruby-doc.org/core/classes/Array.html http://www.manning.com/black/ Josh -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060720/c87fcf9e/attachment-0001.html