aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2010-10-19 16:13:06 +0100
committerJon Leighton <j@jonathanleighton.com>2010-10-19 16:13:06 +0100
commit915ea5ea826d48107e4c1953c7a32cf26727d10e (patch)
tree6d9c1284df9ac076d2b083737374f6b884f7197b /activerecord/test/cases
parent0ceb34295501a797c9e549c581ecee17f837f01c (diff)
downloadrails-915ea5ea826d48107e4c1953c7a32cf26727d10e.tar.gz
rails-915ea5ea826d48107e4c1953c7a32cf26727d10e.tar.bz2
rails-915ea5ea826d48107e4c1953c7a32cf26727d10e.zip
Support the :primary_key option on a through reflection in a nested through association
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/associations/nested_has_many_through_associations_test.rb17
1 files changed, 16 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 c39ec5d139..3a4601b032 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
@@ -21,6 +21,7 @@ require 'models/organization'
require 'models/category'
require 'models/categorization'
require 'models/membership'
+require 'models/essay'
# NOTE: Some of these tests might not really test "nested" HMT associations, as opposed to ones which
# are just one level deep. But it's all the same thing really, as the "nested" code is being
@@ -31,7 +32,7 @@ class NestedHasManyThroughAssociationsTest < ActiveRecord::TestCase
fixtures :authors, :books, :posts, :subscriptions, :subscribers, :tags, :taggings,
:people, :readers, :references, :jobs, :ratings, :comments, :members, :member_details,
:member_types, :sponsors, :clubs, :organizations, :categories, :categories_posts,
- :categorizations, :memberships
+ :categorizations, :memberships, :essays
# Through associations can either use the has_many or has_one macros.
#
@@ -440,6 +441,20 @@ class NestedHasManyThroughAssociationsTest < ActiveRecord::TestCase
end
end
+ def test_nested_has_many_through_with_foreign_key_option_on_the_source_reflection_through_reflection
+ assert_equal [categories(:general)], organizations(:nsa).author_essay_categories
+
+ organizations = Organization.joins(:author_essay_categories).
+ where('categories.id' => categories(:general).id)
+ assert_equal [organizations(:nsa)], organizations
+
+ assert_equal categories(:general), organizations(:nsa).author_owned_essay_category
+
+ organizations = Organization.joins(:author_owned_essay_category).
+ where('categories.id' => categories(:general).id)
+ assert_equal [organizations(:nsa)], organizations
+ end
+
private
def assert_includes_and_joins_equal(query, expected, association)