Association count caching

Hi all,

5.times { foo.association }

will produce 1 query to the DB; the result is “cached” (for want of a
better word) in a variable somewhere. However:

5.times { foo.association.count }

will run the query 5 times. Why?

I could use an association extension to cache the count value for me,
but first I want to understand whether this is a bad idea and has been
deliberately avoided?


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs