Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
编写具有 counter_cache 列的夹具既繁琐又复杂,我尝试在 test_helper.rb 中使用方法 reset_counters 但它不起作用。同样的方式让它工作?
我使用猴子路径在测试环境中禁用 counter_cache 解决了这个问题。
配置/环境/test.rb
module ActiveRecord::Associations class HasManyAssociation def has_cached_counter?(reflection = reflection()) false end end end