3 ms·
In Rails 4, User.count and User.all.count both do the same thing: SELECT COUNT(*) FROM "users" In earlier versions, User.all.count executes: SELECT "user
by chaz 13y ago
In Rails 4, User.count and User.all.count both do the same thing:
SELECT COUNT(*) FROM "users"
In earlier versions, User.all.count executes:
SELECT "users".* FROM "users"
because it is pulling back all fields from all users into memory, instead of just asking the database to check the index for a count.
- meowface 13y agoThis is an easy mix-up to make considering .length, .count, and .size are all aliases.