Fork me on GitHub

Zeke Sikelianos

Mumblings from the code swamp. Find my more interesting online-ness at zeke.sikelianos.com.

ActiveRecord Associations: Count vs. Size vs. Length

Short answer: use size. It will give you a count of the objects without actually loading them, and it’s smart enough to avoid hitting the database if the association has already been loaded. Furthermore, it picks up on counter caches when you follow naming conventions. More info at Robot Has No Heart.


Page 1 of 1