Archive for the ‘rails’ Category

August 5

Beware of Rails Optimistic Locking and MySQL

Posted by mtoledo
Filed under rails, ruby | 7 Comments

There’s a caveat when using rails optimistic locking inside callbacks in a fault tolerant way with mysql’s default settings. Of course that’s a lot of things and sounds like a very specific scenario, but its not that much. Let me break it down:
Rails optimistic locking
Rails will automatically create locks around a record being updated in [...]

July 1

Watch out for using ActiveRecord’s update_attributes on dirty objects

Posted by mtoledo
Filed under rails, ruby | 2 Comments

I’ve recently found out a very odd particularity about how ActiveRecord behaves when relationship properties through the update_attributes method in ActiveRecord::Base. In fact due to its simple implementation, its actually a behavior of any saving of relationships on dirty records.

# in rails ActiveRecord::Base (base.rb)

# Updates all the attributes from the passed-in Hash and saves the [...]