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")
  }

ShiftEntry作成shift_notes_count時に増やさない方法shift_note.state.canceled? => true

現在、私のshift_entries_countは読み取り専用です。

4

1 に答える 1

0

所属先に条件を設定できます。これがあなたが求めているものだと思います:

belongs_to :shift, :counter_cache => lambda {|c| !c.state.canceled }
于 2013-10-21T16:31:46.667 に答える