diff options
author | Mack Earnhardt <mack@agilereasoning.com> | 2013-03-16 12:32:07 -0400 |
---|---|---|
committer | Mack Earnhardt <mack@agilereasoning.com> | 2013-03-17 02:11:19 -0400 |
commit | 1d6eabb67758dd607f8cbcd38da76eb2c9146844 (patch) | |
tree | 02e3644bb298c558bf79df1bc20a6c01d0266ee2 /activerecord/test/models | |
parent | 077031691df0070be39a965a7eee07a9e5b1c4fe (diff) | |
download | rails-1d6eabb67758dd607f8cbcd38da76eb2c9146844.tar.gz rails-1d6eabb67758dd607f8cbcd38da76eb2c9146844.tar.bz2 rails-1d6eabb67758dd607f8cbcd38da76eb2c9146844.zip |
Refactor Person/Friendship relationships to be more intuitive
PR #5210 added a Friendship model to illustrate a bug, but in doing so
created a confusing structure because both belongs_to declarations in
Friendship referred to the same side of the join. The new structure
maintains the integrity of the bug test while changing the follower
relationship to be more useful for other testing.
Diffstat (limited to 'activerecord/test/models')
-rw-r--r-- | activerecord/test/models/friendship.rb | 4 | ||||
-rw-r--r-- | activerecord/test/models/person.rb | 5 |
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 |