Strange behaviour in ActiveRecord transaction


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






#self.number==1 ***Reverted!


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?


it’s Rails 2.3.2 on Windows (Vista).


and MySQL 5.0


Perhaps some validation fails on self. Try save! To raise an exception

2009/5/28, Sandworth M. removed_email_address@domain.invalid:

and MySQL 5.0

Posted via

Von meinen Mobilgerät aus gesendet


I just noticed that in the code sample I submitted, I actually
wrote “self.number=”. In my original code I had “number=”.


This was not an issue with ActiveRecord/Rails.
(I had to use “self.number=” instead of “number=”. Using “number=”
wasn’t actually calling the function “number=”,
but I presume was creating a local variable “number” instead.)