aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/models
diff options
context:
space:
mode:
authorDave Desrochers <dave726@gmail.com>2012-02-28 10:20:27 -0800
committerRafael Mendonça França <rafaelmfranca@gmail.com>2012-08-21 14:10:11 -0300
commitff0d9b93b9074c479dd6de657c71812f0ac40cbe (patch)
treedfad842195953c034096ef46e8d0c305f37499aa /activerecord/test/models
parentce0dd56183d198739638c2cfa7c17f90513a7072 (diff)
downloadrails-ff0d9b93b9074c479dd6de657c71812f0ac40cbe.tar.gz
rails-ff0d9b93b9074c479dd6de657c71812f0ac40cbe.tar.bz2
rails-ff0d9b93b9074c479dd6de657c71812f0ac40cbe.zip
reset_counters() was crashing when there were multiple belongs_to associations with the same foreign key.
This closes #5200.
Diffstat (limited to 'activerecord/test/models')
-rw-r--r--activerecord/test/models/friendship.rb4
-rw-r--r--activerecord/test/models/person.rb2
2 files changed, 6 insertions, 0 deletions
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'