In my photos class I have this association.
belongs_to :user, :touch => true
One day I got this exception.
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'
What should I do to prevent future exceptions like this from occurring? I would like the update statement shown in the error to not use locking if possible. I don't think using optimistic locking will work in this case because optimistic locking would probably raise an ActiveRecord::StaleObjectError instead.