Ryan Bigg wrote:> Try User.count or User.all.size.
Unless I missed it it seems that no one actually mentioned the real
difference between these two calls. While they will produce the same end
result the process of getting to that result is very different:
n = User.all.size
=> 123
SELECT * FROM "users"
n = User.count
=> 123
SELECT count(*) AS count_all FROM "users"
Obviously the latter is significantly more efficient.
--
Posted via http://www.ruby-forum.com/.
--
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.