# Temporary disabling after\_update

**URL:** <https://www.ruby-forum.com/t/temporary-disabling-after-update/115219>\
**Category:** Rails\
**Created:** [September 21, 2007, 10:34pm UTC](https://www.ruby-forum.com/t/temporary-disabling-after-update/115219 "2007-09-21T22:34:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![glenn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4bbf92/32.png) [@glenn](https://www.ruby-forum.com/u/glenn)\
**Post date:** [September 21, 2007, 10:34pm UTC](https://www.ruby-forum.com/t/temporary-disabling-after-update/115219/1 "2007-09-21T22:34:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![glenn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4bbf92/32.png) [@glenn](https://www.ruby-forum.com/u/glenn)\
**Post date:** [September 22, 2007, 4:29am UTC](https://www.ruby-forum.com/t/temporary-disabling-after-update/115219/2 "2007-09-22T04:29:18Z")

</div>

Interestingly enough, update\_all does not call after\_update, so I  
just settled with following code for now.  
Please let me know if you have smarter solutions.

def after\_update  
Action.update\_all(“latest = ‘’”, [“inquiry\_id = ?”,  
self.inquiry\_id])  
latest\_action = Action.find(:first, :conditions =\> [“deleted \<\> 1  
and inquiry\_id = ?”, self.inquiry\_id], :order =\> “action\_date DESC, id  
DESC”)  
Action.update\_all(“latest = ‘Y’”, [“id = ?”, latest\_action.id]) if  
latest\_action  
end
