Hi,
I'm using an ActiveRecord transaction in a Rails app,
and one of the changes made during the transaction is reverted
as the transaction finishes, whilst the other changes are preserved.
The code is like:
------------------------
def swap(other)
self_number=self.number #==1
other_number=other.number #==2
ActiveRecordModel.transaction do
version=Version.find_by_kind(self.kind)
#version.number==30
self.number=other_number
other.number=self_number
self.save
other.save
version.number+=1
version.save
#self.number==2
#other.number==1
#version.number==31
end
#self.number==1 ***Reverted!
#other.number==1
#version.number=31
end
------------------------
No exception is being raised by the transaction. Also, I've tried
reversing the order of the assignment and saving on self and other, but
it's still just self.number that reverts. Any ideas?
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---