svenfuchs/globalize3 — pull request #256 by shioyama (2013-07-20 03:05:26+00:00)
Title: do not autosave translation to avoid additional db update when translation is cached

I've pulled over the [`create_row_test`](https://github.com/svenfuchs/globalize3/blob/rails4/test/create_row_test.rb) from the rails4 branch and trimmed it down to a single test that checks whether an update is performed when saving a record with a cached translation.

The problem is easy to solve: just pass an `:autosave => false` option to `has_many` when creating the translations association.

From the [docs](http://api.rubyonrails.org/classes/ActiveRecord/AutosaveAssociation.html):

> Note that autosave: false is not same as not declaring :autosave. When the :autosave option is not present then new association records are saved but the updated association records are not saved.

So the problem is that when a translation is cached on a new instance, rails will save the translation once when saving the record but with a nil value for translated attributes, then update it in `save_translations` with the translated attribute value. It should just save it in one step.

I don't see any other failures so I think this is just something that has been missed because it's not obvious.

If this is okay I'll merge it to the rails4 branch as well.