rails/rails — pull request #7824 by al2o3cr (2012-10-02 22:09:33+00:00)
Title: Break cycles when autosaving

This is a draft of a fix for #7809 - there's still one failing test, but I'm not certain how to fix it.

The failing test verifies that only a single query is executed when updating a record with autosave on its assocations. Adding `:inverse_of` causes the related objects (Birds, in this case) to pick up the still-saving parent object (Pirate in this case) and save it again.

The net result is that duplicate `UPDATE` queries are sent. While this is certainly an improvement over the existing behavior (which recurses infinitely in `changed_for_autosave?`) it's still wrong.

Thoughts on how to fix this? The parent record clearly should be savable again, to accommodate code that updates the parent in, say, an `after_save` on child records. `define_non_cyclic_method` already avoids the cycle in that case, so the saves don't recurse indefinitely.