rails/rails — pull request #14282 by fshowalter (2014-03-05 03:57:20+00:00)
Title: Update CollectionAssociation.ids_writer to update changed_attributes

Currently, ActiveRecord implements partial support for dirty attributes.

```ruby
post = Post.new(title: "Test Post")
post.changed_attributes # => {"title" => nil }
```

This works great for everything except the common use case of collection lookups.

For example, suppose our app allowed the user to pick from a list of tags. We could use a multi-select or a checkbox array, but the end result would be something like this:

```ruby
post = Post.new(title: "New Post", tag_ids: ['1','2','3'])
post.changed_attributes # => {"title" => nil }
```

With this pull request, you'd get:

```ruby
post = Post.new(title: "New Post", tag_ids: ['1','2','3'])
post.changed_attributes # => {"title" => nil, "tag_ids" => [] }
```

This isn't intended to be a be-all-end-all implementation of changed_attributes for associations, just one that covers the common use case of has_many associations that are only associations from a normalization standpoint and thus exclusively make use of the `ids_writer` method to update via the owner.