# After\_update race condition

**URL:** <https://www.ruby-forum.com/t/after-update-race-condition/128684>\
**Category:** Rails\
**Created:** [February 10, 2008, 2:43pm UTC](https://www.ruby-forum.com/t/after-update-race-condition/128684 "2008-02-10T14:43:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ankit2584](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/51bf81/32.png) [@ankit2584](https://www.ruby-forum.com/u/ankit2584)\
**Post date:** [February 10, 2008, 2:43pm UTC](https://www.ruby-forum.com/t/after-update-race-condition/128684/1 "2008-02-10T14:43:42Z")

</div>

Hello,  
I have two models. people and organisations  
they have a many to many relationship between them.  
I want to be able to create person in an organisation form and vice  
versa.  
the forms for them are according to the railscasts episode 75  
complex\_forms\_3. which is as follows

I have a organisation form(that is created dynamically) in the person  
form

class Organisation \< ActiveRecord::Base  
has\_and\_belongs\_to\_many :people  
after\_update :save\_organisations

def save\_people  
people.each do|p|  
if p.should\_destroy?  
p.destroy  
else  
p.save(false)  
end  
end  
end  
end

class Person \< ActiveRecord::Base  
has\_and\_belongs\_to\_many :organisations  
after\_update :save\_people

def save\_organisations  
organisations.each do|org|  
if org.should\_destroy?  
org.destroy  
else  
org.save(false)  
end  
end  
end  
end

Now when i create a person or an organisation the process never gets  
complete.  
Only when i comment any one of the after\_update statements The problem  
goes away. But in this case I can either create/update an organisation  
in the person form or a person in an organisation form depending upon  
which after\_update i have disabled.

can anyone tell mne whats going wrong and how do i correct it.

Thank you.
