Counter cache on a habtm relation?
Is it possible to use counter cache on a habtm relation in rails 3 ?
I really need it to speed up my appl开发者_运维问答ication.
There is no built in method for HABTM
but it is simple to make your own counter cache (actually I was doing it many times before I've invented counter_cache
.
Or use has_many :throught
instead of HABTM
association. I never use HABTM
because it looks awkward for me.
Related topic:
counter_cache with has_many :through
For what it's worth, I created a version for HABTM which you can see here.
If you have any questions/comments/suggestions, feel free to leave them - or even fork it and let me see :)
In rails 4, counter_cache
for has_and_belongs_to_many
relation works great.
精彩评论