rails/rails — pull request #15314 by dv (2014-05-25 15:14:40+00:00)
Title: Don't save unchanged parent in has_one through

When the `AutosaveAssociation#save_has_one_association` is called for a `has_one :user, through: :post` association, the following code on line 408 in `autosave_association.rb` is always true:

`record[reflection.foreign_key] != key`

This because `reflection.foreign_key` would return the `Post`s' foreign key `"user_id"`, while `record` is a `User` object. Obviously a `user[:user_id]` is always nil and never equal to the `id` of the object the association is set on.

The symptom is that a parent object is always saved, and callbacks always run, even though there might not be any changes, which according to the call to `record_changed?` is undesirable behaviour.

Fixes #13360