aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/models
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2013-03-16 23:14:11 -0700
committerRafael Mendonça França <rafaelmfranca@gmail.com>2013-03-16 23:14:11 -0700
commitf5ecb133335dbfcb2322e5ce91158cf91f730aea (patch)
tree02e3644bb298c558bf79df1bc20a6c01d0266ee2 /activerecord/test/models
parent077031691df0070be39a965a7eee07a9e5b1c4fe (diff)
parent1d6eabb67758dd607f8cbcd38da76eb2c9146844 (diff)
downloadrails-f5ecb133335dbfcb2322e5ce91158cf91f730aea.tar.gz
rails-f5ecb133335dbfcb2322e5ce91158cf91f730aea.tar.bz2
rails-f5ecb133335dbfcb2322e5ce91158cf91f730aea.zip
Merge pull request #9747 from macksmind/refactor_friend_follower
Refactor Person/Friendship relationships to be more intuitive
Diffstat (limited to 'activerecord/test/models')
-rw-r--r--activerecord/test/models/friendship.rb4
-rw-r--r--activerecord/test/models/person.rb5
2 files changed, 7 insertions, 2 deletions
diff --git a/activerecord/test/models/friendship.rb b/activerecord/test/models/friendship.rb
index 6b4f7acc38..4b411ca8e0 100644
--- a/activerecord/test/models/friendship.rb
+++ b/activerecord/test/models/friendship.rb
@@ -1,4 +1,6 @@
class Friendship < ActiveRecord::Base
belongs_to :friend, class_name: 'Person'
- belongs_to :follower, foreign_key: 'friend_id', class_name: 'Person', counter_cache: :followers_count
+ # friend_too exists to test a bug, and probably shouldn't be used elsewhere
+ belongs_to :friend_too, foreign_key: 'friend_id', class_name: 'Person', counter_cache: :friends_too_count
+ belongs_to :follower, class_name: 'Person'
end
diff --git a/activerecord/test/models/person.rb b/activerecord/test/models/person.rb
index fa717ef8d6..2985160d28 100644
--- a/activerecord/test/models/person.rb
+++ b/activerecord/test/models/person.rb
@@ -8,7 +8,10 @@ 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 :friendships, foreign_key: 'friend_id'
+ # friends_too exists to test a bug, and probably shouldn't be used elsewhere
+ has_many :friends_too, foreign_key: 'friend_id', class_name: 'Friendship'
+ has_many :followers, through: :friendships
has_many :references
has_many :bad_references