From cafdbeba9043c25280fb816ec5e554ae2d020f86 Mon Sep 17 00:00:00 2001 From: Michel Pigassou Date: Sat, 30 Jul 2016 15:19:30 +0200 Subject: 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). --- activerecord/lib/active_record/relation/finder_methods.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'activerecord/lib/active_record') 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 -- cgit v1.2.3