4
counter_cache增量和減量火災active_record回調?Rails的ActiveRecord CounterCache和回調
User << AR
has_many :cups
after_update :do_something
def do_something
"Will I be called when number of cups updated ?"
end
end
Cup << AR
belongs_to :user, counter_cache: true
end
在上面的代碼會在添加新的杯子功能do_something被調用,它屬於一個用戶,更新將被要求用戶更新cups_count,但是從我已經嘗試過了,似乎像counter_cache更新不會觸發回調,可能是因爲它們本身在回調中?
感謝