0

레일 3.2에서 연결 옵션 counter_cachecounter_sql 또는 conditions과 같은 다른 옵션에 연결되어 있습니까? 예를 들어카운터 캐시가 counter_sql 또는 조건을 존중합니까?

, I가있는 경우 등이 연관 :

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)을 사용하십시오. 이렇게하면 콜백이 재귀 적으로 호출되지 않도록 할 수 있습니다.