aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorMichel Pigassou <mpigassou@zendesk.com>2016-07-30 15:19:30 +0200
committerMichel Pigassou <mpigassou@zendesk.com>2016-08-13 12:41:45 -0700
commitcafdbeba9043c25280fb816ec5e554ae2d020f86 (patch)
treec9904aa5466cabbf8114d012af51b80b1ba13228 /activerecord/lib
parent6107a40c0e4d05614493bddf33d5ae8d9ce8a8d2 (diff)
downloadrails-cafdbeba9043c25280fb816ec5e554ae2d020f86.tar.gz
rails-cafdbeba9043c25280fb816ec5e554ae2d020f86.tar.bz2
rails-cafdbeba9043c25280fb816ec5e554ae2d020f86.zip
When calling association.find RecordNotFound is now raised with the same argument as when we do it in Record.find (primary_key, id and model).
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/relation/finder_methods.rb10
1 files changed, 6 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb
index 7bf84c2f15..8c85e10389 100644
--- a/activerecord/lib/active_record/relation/finder_methods.rb
+++ b/activerecord/lib/active_record/relation/finder_methods.rb
@@ -348,15 +348,17 @@ module ActiveRecord
def raise_record_not_found_exception!(ids, result_size, expected_size) #:nodoc:
conditions = arel.where_sql(@klass.arel_engine)
conditions = " [#{conditions}]" if conditions
+ name = @klass.name
if Array(ids).size == 1
- error = "Couldn't find #{@klass.name} with '#{primary_key}'=#{ids}#{conditions}"
+ error = "Couldn't find #{name} with '#{primary_key}'=#{ids}#{conditions}"
+ raise RecordNotFound.new(error, name, primary_key, ids)
else
- error = "Couldn't find all #{@klass.name.pluralize} with '#{primary_key}': "
+ error = "Couldn't find all #{name.pluralize} with '#{primary_key}': "
error << "(#{ids.join(", ")})#{conditions} (found #{result_size} results, but was looking for #{expected_size})"
- end
- raise RecordNotFound, error
+ raise RecordNotFound, error
+ end
end
private