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

How to not increase shift_notes_count when during ShiftEntry creation shift_note.state.canceled? => true

Right now my shift_entries_count is read-only.

tomekfranek
  • 6,852
  • 8
  • 45
  • 80

1 Answers1

0

You could set a conditional on the belongs to, I think this is what you're asking for:

belongs_to :shift, :counter_cache => lambda {|c| !c.state.canceled }
trh
  • 7,186
  • 2
  • 29
  • 41