mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
belongs_to associations now honor :primary_key option for joins
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
This commit is contained in:
committed by
Jeremy Kemper
parent
03d5d0b5f5
commit
00b95eb265
@@ -2173,7 +2173,7 @@ module ActiveRecord
|
||||
" #{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 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase
|
||||
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 }
|
||||
|
||||
Reference in New Issue
Block a user