Permalink
Browse files

Prefix primary key with table name so it works as part of a joined fetch

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1086 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 2cfe309 commit 9e799e731c7960e37ea928371e93590a79f36000 @dhh dhh committed Apr 4, 2005
Showing with 2 additions and 2 deletions.
  1. +2 −2 activerecord/lib/active_record/base.rb
View
4 activerecord/lib/active_record/base.rb
@@ -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

0 comments on commit 9e799e7

Please sign in to comment.