Rails: How to find out how many items stored in database?
To find out how many jobs are stored in database I do:
Job.all.size
Is this th开发者_如何学Ce best way to do this ?
You can do:
Job.count
This will do a
SELECT COUNT(*) FROM "jobs"
in the database...
The size will use the counter cache field if available.
The count always perform the database query.
精彩评论