Skip to content

Commit

Permalink
belongs_to associations now honor :primary_key option for joins
Browse files Browse the repository at this point in the history
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information
Ernie Miller authored and jeremy committed Mar 29, 2010
1 parent 03d5d0b commit 00b95eb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/associations.rb
Expand Up @@ -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
]
Expand Down
Expand Up @@ -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 }
Expand Down

0 comments on commit 00b95eb

Please sign in to comment.