0

在Rails 3.2中,關聯選項counter_cache與其他選項鍊接,如counter_sqlconditions計數器緩存尊重counter_sql或條件?

舉例來說,如果我有這樣的關聯:

class User 
    has_many :items, :through => :orders 
    has_many :active_items, :through => :orders 
      :conditions => 'active = true', :source => :item 

class Order 
    belongs_to :users, :counter_cache => :active_items_count 
    belongs_to :items 

class Item 
    has_many :users, :through => :orders 

會將反緩存就該活躍條件? (意思是不活動的項目將不計算在內) 又是怎麼回事使用finder_sql/counter_sql

回答

0

我結束了很少使用計數器緩存你提到的原因,而是,始終創造我自己的。響應on_save和on_create回調並調用一個方法來更新計數。

一個提示,如果你創建你自己的,使用@instance.update_column(:column, value)。這將確保回調不會被遞歸調用。