diff options
author | David Peter <david.a.peter@gmail.com> | 2012-01-16 18:06:14 -0800 |
---|---|---|
committer | David Peter <david.a.peter@gmail.com> | 2012-01-16 19:06:45 -0800 |
commit | ee013a503db125b8be54daec7096e2d26bb6228c (patch) | |
tree | ccb096e2f9fe053ffe1538b9276c6632973abda8 /activerecord/test/models | |
parent | 21afd9b96d70d1e2b1cffdfb60f7ec64ab240472 (diff) | |
download | rails-ee013a503db125b8be54daec7096e2d26bb6228c.tar.gz rails-ee013a503db125b8be54daec7096e2d26bb6228c.tar.bz2 rails-ee013a503db125b8be54daec7096e2d26bb6228c.zip |
Fix bug where reset_counters resets the wrong counter cache.
If a model belongs_to two associations with the same class, then reset_counters
will reset the wrong counter cache.
Finding the right reflection should use the foreign_key instead, which should
be unique.
Diffstat (limited to 'activerecord/test/models')
-rw-r--r-- | activerecord/test/models/dog.rb | 4 | ||||
-rw-r--r-- | activerecord/test/models/dog_lover.rb | 4 |
2 files changed, 8 insertions, 0 deletions
diff --git a/activerecord/test/models/dog.rb b/activerecord/test/models/dog.rb new file mode 100644 index 0000000000..72b7d33a86 --- /dev/null +++ b/activerecord/test/models/dog.rb @@ -0,0 +1,4 @@ +class Dog < ActiveRecord::Base + belongs_to :breeder, :class_name => "DogLover", :counter_cache => :bred_dogs_count + belongs_to :trainer, :class_name => "DogLover", :counter_cache => :trained_dogs_count +end diff --git a/activerecord/test/models/dog_lover.rb b/activerecord/test/models/dog_lover.rb new file mode 100644 index 0000000000..a33dc575c5 --- /dev/null +++ b/activerecord/test/models/dog_lover.rb @@ -0,0 +1,4 @@ +class DogLover < ActiveRecord::Base + has_many :trained_dogs, :class_name => "Dog", :foreign_key => :trainer_id + has_many :bred_dogs, :class_name => "Dog", :foreign_key => :breeder_id +end |