aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2010-10-12 17:32:52 +0100
committerJon Leighton <j@jonathanleighton.com>2010-10-12 17:32:52 +0100
commit56064aa4b014233ae54413628679b7f7fa5d6f77 (patch)
treed4b5c88de4ad32ab23cebff39c1518e38cc46480 /activerecord
parentdc39aceb94fa810f8d7e263c0293f325fbf9a109 (diff)
downloadrails-56064aa4b014233ae54413628679b7f7fa5d6f77.tar.gz
rails-56064aa4b014233ae54413628679b7f7fa5d6f77.tar.bz2
rails-56064aa4b014233ae54413628679b7f7fa5d6f77.zip
Add test_has_many_through_has_one_through_with_has_many_source_reflection
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/test/cases/associations/nested_has_many_through_associations_test.rb19
-rw-r--r--activerecord/test/models/member.rb1
2 files changed, 19 insertions, 1 deletions
diff --git a/activerecord/test/cases/associations/nested_has_many_through_associations_test.rb b/activerecord/test/cases/associations/nested_has_many_through_associations_test.rb
index 4b5ce6313a..7c4bffaddd 100644
--- a/activerecord/test/cases/associations/nested_has_many_through_associations_test.rb
+++ b/activerecord/test/cases/associations/nested_has_many_through_associations_test.rb
@@ -134,9 +134,26 @@ class NestedHasManyThroughAssociationsTest < ActiveRecord::TestCase
members.first.organization_member_details
end
- # TODO: has_many through
+ # has_many through
# Source: has_many
# Through: has_one through
+ def test_has_many_through_has_one_through_with_has_many_source_reflection
+ assert_equal [member_details(:groucho), member_details(:some_other_guy)],
+ members(:groucho).organization_member_details_2
+
+ members = Member.joins(:organization_member_details_2).
+ where('member_details.id' => member_details(:groucho).id)
+ assert_equal [members(:groucho), members(:some_other_guy)], members
+
+ members = Member.joins(:organization_member_details_2).
+ where('member_details.id' => 9)
+ assert members.empty?
+
+ # TODO: Make this work
+ # members = Member.includes(:organization_member_details_2)
+ # assert_equal [member_details(:groucho), member_details(:some_other_guy)],
+ # members.first.organization_member_details_2
+ end
# TODO: has_many through
# Source: has_and_belongs_to_many
diff --git a/activerecord/test/models/member.rb b/activerecord/test/models/member.rb
index 1113ef3e28..44c10cc4a4 100644
--- a/activerecord/test/models/member.rb
+++ b/activerecord/test/models/member.rb
@@ -17,4 +17,5 @@ class Member < ActiveRecord::Base
has_one :nested_sponsor, :through => :sponsor_club, :source => :sponsor
has_many :organization_member_details, :through => :member_detail
+ has_many :organization_member_details_2, :through => :organization, :source => :member_details
end