Wednesday, September 18, 2013

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

Hi Coriordan,
That worked for me, many thanks, but only drawback is, delete_all wont call the callbacks in children classes.



On Friday, January 11, 2013 3:57:39 PM UTC+5:30, coriordan wrote:
The only workaround to this I've been able to find is to use :dependent => :delete_all. This performs a general delete of related objects and doesn't update the lock_version on the parent.

Cathal.

On Thursday, 10 January 2013 16:29:22 UTC, coriordan wrote:
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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/c278adda-aa49-4db0-8acc-b6c91626a13b%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate