aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations/has_many_through_associations_test.rb
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2010-10-19 12:47:19 +0100
committerJon Leighton <j@jonathanleighton.com>2010-10-19 12:47:19 +0100
commit596cc3b2329a9cc4a30c95c157ce36b2d08975df (patch)
tree2a67f6a9270bb528ad5df8bc805f2ef121e93858 /activerecord/test/cases/associations/has_many_through_associations_test.rb
parent9ec07348749675110843c44f680da79223218db2 (diff)
downloadrails-596cc3b2329a9cc4a30c95c157ce36b2d08975df.tar.gz
rails-596cc3b2329a9cc4a30c95c157ce36b2d08975df.tar.bz2
rails-596cc3b2329a9cc4a30c95c157ce36b2d08975df.zip
Respect the :primary_key option on the through_reflection of (non-nested) through associations
Diffstat (limited to 'activerecord/test/cases/associations/has_many_through_associations_test.rb')
-rw-r--r--activerecord/test/cases/associations/has_many_through_associations_test.rb19
1 files changed, 18 insertions, 1 deletions
diff --git a/activerecord/test/cases/associations/has_many_through_associations_test.rb b/activerecord/test/cases/associations/has_many_through_associations_test.rb
index 4b9f49f1ec..5a2e6b26aa 100644
--- a/activerecord/test/cases/associations/has_many_through_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -17,11 +17,14 @@ require 'models/developer'
require 'models/subscriber'
require 'models/book'
require 'models/subscription'
+require 'models/essay'
+require 'models/category'
class HasManyThroughAssociationsTest < ActiveRecord::TestCase
fixtures :posts, :readers, :people, :comments, :authors,
:owners, :pets, :toys, :jobs, :references, :companies,
- :subscribers, :books, :subscriptions, :developers
+ :subscribers, :books, :subscriptions, :developers,
+ :essays, :categories
# Dummies to force column loads so query counts are clean.
def setup
@@ -449,4 +452,18 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
comment = post.comments.build
assert author.comments.include?(comment)
end
+
+ def test_has_many_through_polymorphic_with_primary_key_option_on_through_reflection
+ assert_equal [categories(:general)], authors(:david).essay_categories
+
+ authors = Author.joins(:essay_categories).where('categories.id' => categories(:general).id)
+ assert_equal authors(:david), authors.first
+ end
+
+ def test_has_many_through_with_primary_key_option_on_through_reflection
+ assert_equal [categories(:general)], authors(:david).essay_categories_2
+
+ authors = Author.joins(:essay_categories_2).where('categories.id' => categories(:general).id)
+ assert_equal authors(:david), authors.first
+ end
end