Hi,
I am trying to replace my old database trigger with ActiveRecord
callbacks in rails.
I have a model like following:
class Action < ActiveRecord::Base
belongs_to :inquiry
def after_update
#clean up all action associated with the inquiry.
Action.update_all(“latest = ‘’”, [“inquiry_id = ?”,
self.inquiry_id])
#find the latest action
latest_action = Action.find(:first, :conditions => [“deleted <> 1
and inquiry_id = ?”, self.inquiry_id], :order => “action_date DESC, id
DESC”)
#mark ‘Y’ to the latest action.
latest_action.update_attribute(“latest”, “Y”) if latest_action
end
end
Model “Inquiry” has many “actions”, so I want to maintain the field
called “latest” to indicate the latest action.
However, this will not work. My after_update call another update, and
after_update is recursively called. This will end up with getting
stack overflow.
Are there any way to temporary disable after_update callbacks?
Thanks,
Glen