Thursday, January 10, 2013

[Rails] deleting model using optimistic locking results in ActiveRecord::StaleObjectError

Hi,

I have a model defined like so:

class Course < ActiveRecord::Base
  has_many :attendances, :dependent => :destroy
  has_many :attendees, :through => :attendances, :source => :user

...

when I attempt to delete a Course model, it results in an ActiveRecord::StaleObjectError. Reviewing the resulting SQL calls shows that the 'lock_version' column gets incremented on each dependent 'Attendance' model that is deleted. When the Course model is deleted, its lock_version no longer matches the persisted row in the database, and hence the StaleObjectError. Any help on how to handle this situation would be greatly appreciated.

regards,
Cathal.

--
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/z94yktQoBE0J.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate