diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-02-14 20:39:51 +0000 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2011-02-18 00:00:13 +0000 |
commit | f0b98050296b57d95dbc789f8e52fa82499d151a (patch) | |
tree | 817c7fa99ab5119b6db4a95f5fe2f415975cae54 /activerecord/test | |
parent | b131cfba055bfbf25f3785c5235c1edbf04ff9f1 (diff) | |
download | rails-f0b98050296b57d95dbc789f8e52fa82499d151a.tar.gz rails-f0b98050296b57d95dbc789f8e52fa82499d151a.tar.bz2 rails-f0b98050296b57d95dbc789f8e52fa82499d151a.zip |
Ensure that association_ids uses the correct attribute where the association is a has_many :through with a :primary_key option on the source reflection. [#6376 state:resolved]
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/associations/has_many_through_associations_test.rb | 10 | ||||
-rw-r--r-- | activerecord/test/models/post.rb | 1 |
2 files changed, 11 insertions, 0 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 73b1d6c500..7e77539fe7 100644 --- a/activerecord/test/cases/associations/has_many_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb @@ -718,4 +718,14 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase assert_equal post.tags, post.interpolated_tags assert_equal post.tags, post.interpolated_tags_2 end + + def test_primary_key_option_on_source + post = posts(:welcome) + category = categories(:general) + categorization = Categorization.create!(:post_id => post.id, :named_category_name => category.name) + + assert_equal [category], post.named_categories + assert_equal [category.name], post.named_category_ids # checks when target loaded + assert_equal [category.name], post.reload.named_category_ids # checks when target no loaded + end end diff --git a/activerecord/test/models/post.rb b/activerecord/test/models/post.rb index 5f29196790..1bbcab3a39 100644 --- a/activerecord/test/models/post.rb +++ b/activerecord/test/models/post.rb @@ -90,6 +90,7 @@ class Post < ActiveRecord::Base has_many :standard_categorizations, :class_name => 'Categorization', :foreign_key => :post_id has_many :author_using_custom_pk, :through => :standard_categorizations has_many :authors_using_custom_pk, :through => :standard_categorizations + has_many :named_categories, :through => :standard_categorizations has_many :readers has_many :readers_with_person, :include => :person, :class_name => "Reader" |