rails/rails — pull request #9786 by laserlemon (2013-03-18 21:58:02+00:00)
Title: Ensure that has_many :through counter cache decrements aren't doubled up

A has_many :through association must manage the counter cache of its
join model in case the join model is simply deleted (without callbacks)
rather than destroyed when the association is cleared.

The problem is that if :dependent => :destroy is specified on the
has_many :through, the join model will be destroyed (triggering
callbacks). This means that the join model will decrement the counter
cache in addition to the has_many :througha association. As a result,
the counter cache is decremented twice.

The has_many :through association should only try to manage the counter
cache if the join model is not destroyed.