diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-05-26 13:08:10 -0700 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2011-05-26 13:08:10 -0700 |
commit | 602fff1f58dff5cfdf861b48626b32f99fe27246 (patch) | |
tree | 2fdfc00803474852ab3148d5738d3de2bfa152c7 | |
parent | 09e431aa893bb1d08705381e2bfcd006de22a70e (diff) | |
parent | f4ed56df43b1f88dca46b1a343ede55e649b327e (diff) | |
download | rails-602fff1f58dff5cfdf861b48626b32f99fe27246.tar.gz rails-602fff1f58dff5cfdf861b48626b32f99fe27246.tar.bz2 rails-602fff1f58dff5cfdf861b48626b32f99fe27246.zip |
Merge pull request #1323 from fx/association_primary_key
use association_primary_key in AssociationScope#add_constraints
-rw-r--r-- | activerecord/lib/active_record/associations/association_scope.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb | 10 |
2 files changed, 11 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/association_scope.rb b/activerecord/lib/active_record/associations/association_scope.rb index 94847bc2ae..9e6d9e73c5 100644 --- a/activerecord/lib/active_record/associations/association_scope.rb +++ b/activerecord/lib/active_record/associations/association_scope.rb @@ -60,7 +60,7 @@ module ActiveRecord scope = scope.joins(join( join_table, - table[reflection.active_record_primary_key]. + table[reflection.association_primary_key]. eq(join_table[reflection.association_foreign_key]) )) diff --git a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb index f4d14853d3..839a7852fc 100644 --- a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb @@ -100,6 +100,16 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase assert_equal 'c1', record[0] assert_equal 't1', record[1] end + + def test_proper_usage_of_primary_keys_and_join_table + setup_data_for_habtm_case + + assert_equal 'country_id', Country.primary_key + assert_equal 'treaty_id', Treaty.primary_key + + country = Country.first + assert_equal 1, country.treaties.count + end def test_has_and_belongs_to_many david = Developer.find(1) |