Skip to content
This repository
Browse code

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...
commit 9e799e731c7960e37ea928371e93590a79f36000 1 parent 2cfe309
David Heinemeier Hansson dhh authored

Showing 1 changed file with 2 additions and 2 deletions. Show diff stats Hide diff stats

  1. +2 2 activerecord/lib/active_record/base.rb
4 activerecord/lib/active_record/base.rb
@@ -318,7 +318,7 @@ def find(*args)
318 318 when 0
319 319 raise RecordNotFound, "Couldn't find #{name} without an ID#{conditions}"
320 320 when 1
321   - if result = find(:first, options.merge({ :conditions => "#{primary_key} = #{sanitize(ids.first)}#{conditions}" }))
  321 + if result = find(:first, options.merge({ :conditions => "#{table_name}.#{primary_key} = #{sanitize(ids.first)}#{conditions}" }))
322 322 return expects_array ? [ result ] : result
323 323 else
324 324 raise RecordNotFound, "Couldn't find #{name} with ID=#{ids.first}#{conditions}"
@@ -326,7 +326,7 @@ def find(*args)
326 326 else
327 327 # Find multiple ids
328 328 ids_list = ids.map { |id| sanitize(id) }.join(',')
329   - result = find(:all, options.merge({ :conditions => "#{primary_key} IN (#{ids_list})#{conditions}", :order => primary_key }))
  329 + result = find(:all, options.merge({ :conditions => "#{table_name}.#{primary_key} IN (#{ids_list})#{conditions}", :order => primary_key }))
330 330 if result.size == ids.size
331 331 return result
332 332 else

0 comments on commit 9e799e7

Please sign in to comment.
Something went wrong with that request. Please try again.