Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

use association_primary_key in AssociationScope#add_constraints

(cherry picked from commit 1f7c3d0)
  • Loading branch information...
commit 31023da1b60b574c73c8ef4478b24a6ba7147c84 1 parent 5c498fa
@fx fx authored pixeltrix committed
View
2  activerecord/lib/active_record/associations/association_scope.rb
@@ -60,7 +60,7 @@ def add_constraints(scope)
scope = scope.joins(join(
join_table,
- table[reflection.active_record_primary_key].
+ table[reflection.association_primary_key].
eq(join_table[reflection.association_foreign_key])
))
View
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
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
+
+ country = Country.first
+ assert_equal 1, country.treaties.count
+ end
def test_has_and_belongs_to_many
david = Developer.find(1)
Please sign in to comment.
Something went wrong with that request. Please try again.