我使用了counter_culture gem来跟踪订单has_many Item关联。我的Item模型中有以下计数器:
counter_culture :order, :column_name => Proc.new {|model| model.pending_review? ? 'pending_review_count' : nil }
counter_culture :order, :column_name => Proc.new {|model| model.reviewed? ? 'review_count' : nil }
counter_culture :order, :column_name => Proc.new {|model| model.failed? ? 'fail_count' : nil }
我希望能够在以下情况下调用我的订单的特定方法:
pending_review_count + fail_count == total_count
或
review_count + fail_count == total_count
现在,每次更新一个项目时,我都会检查计数器的值并进行比较,但这似乎有点矫枉过正。有没有办法在Rails中为上述条件设置触发器?