【发布时间】:2011-11-27 02:28:48
【问题描述】:
在我的照片课中,我有这种关联。
belongs_to :user, :touch => true
有一天我遇到了这个异常。
A ActiveRecord::StatementInvalid occurred in photos#update:
Mysql::Error: Deadlock found when trying to get lock; try restarting transaction:
UPDATE `users` SET `updated_at` = '2011-09-20 14:17:44' WHERE `users`.`id` = 6832
production/ruby/1.8/gems/activerecord-3.0.10/lib/active_record/connection_adapters/abstract_adapter.rb:207:in `log'
我应该怎么做才能防止将来发生此类异常?如果可能,我希望错误中显示的更新语句不使用锁定。我不认为在这种情况下使用乐观锁定会起作用,因为乐观锁定可能会引发 ActiveRecord::StaleObjectError。
【问题讨论】:
标签: ruby-on-rails caching locking associations touch