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 14:14:06 +0100
committerJon Leighton <j@jonathanleighton.com>2010-10-19 14:14:06 +0100
commit01838636c6136d9a649ace71db61bb7990f9bd82 (patch)
tree2f307e4dd6843588ab19f7d41615a04465560fff /activerecord/test/cases/associations/has_many_through_associations_test.rb
parent596cc3b2329a9cc4a30c95c157ce36b2d08975df (diff)
downloadrails-01838636c6136d9a649ace71db61bb7990f9bd82.tar.gz
rails-01838636c6136d9a649ace71db61bb7990f9bd82.tar.bz2
rails-01838636c6136d9a649ace71db61bb7990f9bd82.zip
Support for :primary_key option on the source reflection of a through association, where the source is a has_one or has_many
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.rb12
1 files changed, 9 insertions, 3 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 5a2e6b26aa..713c492f5e 100644
--- a/activerecord/test/cases/associations/has_many_through_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -19,12 +19,13 @@ require 'models/book'
require 'models/subscription'
require 'models/essay'
require 'models/category'
+require 'models/owner'
class HasManyThroughAssociationsTest < ActiveRecord::TestCase
fixtures :posts, :readers, :people, :comments, :authors,
:owners, :pets, :toys, :jobs, :references, :companies,
:subscribers, :books, :subscriptions, :developers,
- :essays, :categories
+ :essays, :categories, :owners
# Dummies to force column loads so query counts are clean.
def setup
@@ -453,14 +454,19 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
assert author.comments.include?(comment)
end
- def test_has_many_through_polymorphic_with_primary_key_option_on_through_reflection
+ def test_has_many_through_polymorphic_with_primary_key_option
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
+
+ assert_equal [owners(:blackbeard)], authors(:david).essay_owners
+
+ authors = Author.joins(:essay_owners).where("owners.name = 'blackbeard'")
+ assert_equal authors(:david), authors.first
end
- def test_has_many_through_with_primary_key_option_on_through_reflection
+ def test_has_many_through_with_primary_key_option
assert_equal [categories(:general)], authors(:david).essay_categories_2
authors = Author.joins(:essay_categories_2).where('categories.id' => categories(:general).id)