在我的照片类中,我有这个关联。
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异常。