Skip to content
This repository
Browse code

use association_primary_key in AssociationScope#add_constraints

  • Loading branch information...
commit 1f7c3d02645c6b72e5d1428bc7da6668cdee5fa8 1 parent badc72f
Marian Rudzynski authored May 26, 2011
2  activerecord/lib/active_record/associations/association_scope.rb
@@ -60,7 +60,7 @@ def add_constraints(scope)
60 60
 
61 61
             scope = scope.joins(join(
62 62
               join_table,
63  
-              table[reflection.active_record_primary_key].
  63
+              table[reflection.association_primary_key].
64 64
                 eq(join_table[reflection.association_foreign_key])
65 65
             ))
66 66
 
7  activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
@@ -100,6 +100,13 @@ def test_should_property_quote_string_primary_keys
100 100
     assert_equal 'c1', record[0]
101 101
     assert_equal 't1', record[1]
102 102
   end
  103
+  
  104
+  def test_proper_usage_of_primary_keys_and_join_table
  105
+    setup_data_for_habtm_case
  106
+
  107
+    country = Country.first
  108
+    assert_equal 1, country.treaties.count
  109
+  end
103 110
 
104 111
   def test_has_and_belongs_to_many
105 112
     david = Developer.find(1)

0 notes on commit 1f7c3d0

Please sign in to comment.
Something went wrong with that request. Please try again.