如果计数器具有特定值,则触发方法?

时间:2014-07-14 19:21:38

标签: ruby-on-rails triggers

我使用了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中为上述条件设置触发器?

0 个答案:

没有答案