2013-10-21 32 views
1
ShiftNote 
    belongs_to :shift, counter_cache: true 
    workflow do 
    state :scheduled 
    state :canceled 
    end 
Shift 
    has_many :shift_notes 

    scope :opened, lambda { 
    locked 
    .where("shift_notes_count < shifts.limit") 
    } 

如何不增加shift_notes_count期間ShiftEntry創作時shift_note.state.canceled? => true如何在某些狀態更改時排除遞增的counter_cache?

現在我shift_entries_count是隻讀的。

回答

0

您可以設置一個條件就屬於,我覺得這是你問的:

belongs_to :shift, :counter_cache => lambda {|c| !c.state.canceled } 
+0

Rails不支持有條件的計數器。 – Florent2

相關問題