Skip to content
This repository

use association_primary_key in AssociationScope#add_constraints #1323

Merged
merged 2 commits into from almost 3 years ago

2 participants

Marian Rudzynski Jon Leighton
Marian Rudzynski
fx commented

AssociationScope#add_constraints was incorrectly using Reflection#active_record_primary_key instead of Reflection#association_primary_key (Line 63)

Jon Leighton jonleighton closed this
Jon Leighton jonleighton reopened this
Jon Leighton jonleighton merged commit 602fff1 into from
Jon Leighton jonleighton closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
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
 
10  activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
@@ -100,6 +100,16 @@ 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
+    assert_equal 'country_id', Country.primary_key
  108
+    assert_equal 'treaty_id', Treaty.primary_key
  109
+
  110
+    country = Country.first
  111
+    assert_equal 1, country.treaties.count
  112
+  end
103 113
 
104 114
   def test_has_and_belongs_to_many
105 115
     david = Developer.find(1)
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.