From ff0d9b93b9074c479dd6de657c71812f0ac40cbe Mon Sep 17 00:00:00 2001 From: Dave Desrochers Date: Tue, 28 Feb 2012 10:20:27 -0800 Subject: reset_counters() was crashing when there were multiple belongs_to associations with the same foreign key. This closes #5200. --- activerecord/test/models/friendship.rb | 4 ++++ activerecord/test/models/person.rb | 2 ++ 2 files changed, 6 insertions(+) create mode 100644 activerecord/test/models/friendship.rb (limited to 'activerecord/test/models') diff --git a/activerecord/test/models/friendship.rb b/activerecord/test/models/friendship.rb new file mode 100644 index 0000000000..6b4f7acc38 --- /dev/null +++ b/activerecord/test/models/friendship.rb @@ -0,0 +1,4 @@ +class Friendship < ActiveRecord::Base + belongs_to :friend, class_name: 'Person' + belongs_to :follower, foreign_key: 'friend_id', class_name: 'Person', counter_cache: :followers_count +end diff --git a/activerecord/test/models/person.rb b/activerecord/test/models/person.rb index e204508986..6e6ff29f77 100644 --- a/activerecord/test/models/person.rb +++ b/activerecord/test/models/person.rb @@ -8,6 +8,8 @@ class Person < ActiveRecord::Base has_many :posts_with_no_comments, -> { includes(:comments).where('comments.id is null').references(:comments) }, :through => :readers, :source => :post + has_many :followers, foreign_key: 'friend_id', class_name: 'Friendship' + has_many :references has_many :bad_references has_many :fixed_bad_references, -> { where :favourite => true }, :class_name => 'BadReference' -- cgit v1.2.3