Permalink
Browse files

belongs_to associations now honor :primary_key option for joins

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information...
1 parent 03d5d0b commit 00b95eb265ff606ae0a7b650265aa3c6fd43a1da @ernie ernie committed with jeremy Feb 11, 2010
@@ -2173,7 +2173,7 @@ def association_join
" #{join_type} %s ON %s.%s = %s.%s " % [
table_name_and_alias,
connection.quote_table_name(aliased_table_name),
- reflection.klass.primary_key,
+ reflection.options[:primary_key] || reflection.klass.primary_key,
connection.quote_table_name(parent.aliased_table_name),
options[:foreign_key] || reflection.primary_key_name
]
@@ -31,6 +31,12 @@ def test_belongs_to_with_primary_key
assert_equal companies(:first_firm).name, client.firm_with_primary_key.name
end
+ def test_belongs_to_with_primary_key_joins_on_correct_column
+ sql = Client.send(:construct_finder_sql, :joins => :firm_with_primary_key)
+ assert sql !~ /\.id/
+ assert sql =~ /\.name/
+ end
+
def test_proxy_assignment
account = Account.find(1)
assert_nothing_raised { account.firm = account.firm }

0 comments on commit 00b95eb

Please sign in to comment.