www.akshaykhot.com/rails-length-size-count-difference/
1 Users
0 Comments
4 Highlights
0 Notes
Top Highlights
If you will need the records anyway, use the length method. It will take one less query, since Rails will use the cached records for the later query.
Just like Ruby, Rails offers multiple ways to do the same thing. Unlike The Zen of Python, there's no one obvious way to do it.
Collection proxies are used by ActiveRecord, acting as middlemen between an association and its result set.
If you won't need the records, use the size method as it's more efficient. It will run a COUNT SQL query to fetch the count directly from the database, without loading the records in memory.
Glasp is a social web highlighter that people can highlight and organize quotes and thoughts from the web, and access other like-minded people’s learning.