diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2016-05-12 22:19:17 -0400 |
---|---|---|
committer | Sean Griffin <sean@seantheprogrammer.com> | 2016-05-12 22:20:45 -0400 |
commit | 0991c4c6fc0c04764f34c6b65a42adce190440c3 (patch) | |
tree | 8dc6828aa2a035b11979c948e5dce03f855baf44 /activerecord/lib | |
parent | 8d11a8f253a6c16ffed2bb65d4296e5d4dfd9812 (diff) | |
download | rails-0991c4c6fc0c04764f34c6b65a42adce190440c3.tar.gz rails-0991c4c6fc0c04764f34c6b65a42adce190440c3.tar.bz2 rails-0991c4c6fc0c04764f34c6b65a42adce190440c3.zip |
Give more context from `AssociationMismatchError`
The error message that we give today makes this error difficult to debug
if you receive it. I have no clue why we're printing the object ID of
the class (the commit doesn't give context), but I've left it as it was
deliberate.
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/association.rb | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/association.rb b/activerecord/lib/active_record/associations/association.rb index f7edfbfb5f..62e867a353 100644 --- a/activerecord/lib/active_record/associations/association.rb +++ b/activerecord/lib/active_record/associations/association.rb @@ -217,7 +217,8 @@ module ActiveRecord unless record.is_a?(reflection.klass) fresh_class = reflection.class_name.safe_constantize unless fresh_class && record.is_a?(fresh_class) - message = "#{reflection.class_name}(##{reflection.klass.object_id}) expected, got #{record.class}(##{record.class.object_id})" + message = "#{reflection.class_name}(##{reflection.klass.object_id}) expected, "\ + "got #{record.inspect} which is an instance of #{record.class}(##{record.class.object_id})" raise ActiveRecord::AssociationTypeMismatch, message end end |