rails/rails — pull request #16875 by alan (2014-09-11 09:17:47+00:00)
Title: Don't autosave unchanged has_one through records

`has_one` associations (including `has_one :through`) go through the autosave logic on saves to check if they need to be saved.

Problem is that the logic that decides if a record needs to be autosaved for `has_one :through` always returns true and the record is saved. This causes `after_commit` callbacks to be triggered which can be unexpected.

Taking the example for the test: A Minivan has one Dashboard through Speedometer

Given an existing minivan with a dashboard, if that minivan is saved without changes this appears in the SQL logs:
```
BEGIN
COMMIT
```
The problem is that if Dashboard has `after_commit` callbacks set they get triggered, even though it didn't participate in the transaction.

We've modified the autosave logic check so that the save is not called on `has_one :through` records.

However I think this unexpected behaviour could be two bugs:
* one that this PR fixes, essentially a defensive fix.
* the other one being that `has_one :through` records should not even be attempted to be autosaved. (We aren't sure about this or how to fix without spending more time on it)

What are people thoughts on the issue and proposed fix in general?