开发者

Counter cache on a habtm relation?

开发者 https://www.devze.com 2023-02-26 20:17 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消