rails/rails — pull request #8400 by matthewrobertson (2012-12-02 04:06:07+00:00)
Title: Fixes has many through counter-cache bug

This commit fixes reported [issue #7630](https://github.com/rails/rails/issues/7630) in which counter caches were not being updated properly when replacing has_many_through relationships.

eg if `posts` have many `tags` through `taggings`

and I did:

```ruby
post = Post.create!
tag = post.tags.create!
tag.posts = []
```

then: `post.reload.taggings_count == 1`