Skip to content

Commit

Permalink
Prefix primary key with table name so it works as part of a joined fetch
Browse files Browse the repository at this point in the history
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1086 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
dhh committed Apr 4, 2005
1 parent 2cfe309 commit 9e799e7
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions activerecord/lib/active_record/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -318,15 +318,15 @@ def find(*args)
when 0
raise RecordNotFound, "Couldn't find #{name} without an ID#{conditions}"
when 1
if result = find(:first, options.merge({ :conditions => "#{primary_key} = #{sanitize(ids.first)}#{conditions}" }))
if result = find(:first, options.merge({ :conditions => "#{table_name}.#{primary_key} = #{sanitize(ids.first)}#{conditions}" }))
return expects_array ? [ result ] : result
else
raise RecordNotFound, "Couldn't find #{name} with ID=#{ids.first}#{conditions}"
end
else
# Find multiple ids
ids_list = ids.map { |id| sanitize(id) }.join(',')
result = find(:all, options.merge({ :conditions => "#{primary_key} IN (#{ids_list})#{conditions}", :order => primary_key }))
result = find(:all, options.merge({ :conditions => "#{table_name}.#{primary_key} IN (#{ids_list})#{conditions}", :order => primary_key }))
if result.size == ids.size
return result
else
Expand Down

0 comments on commit 9e799e7

Please sign in to comment.