Permalink
Browse files

Make missed association exception message more informative

Add target class name, which should have missed association on preload,
into exception message to simplify detecting problem part.
  • Loading branch information...
1 parent 3651101 commit 625cd69a8b74a49fe2831983e89536f872c5abe7 @pftg pftg committed Oct 12, 2013
Showing with 9 additions and 3 deletions.
  1. +6 −0 activerecord/CHANGELOG.md
  2. +3 −3 activerecord/lib/active_record/associations/preloader.rb
@@ -1,3 +1,9 @@
+* For missed association exception message
+ which is raised in `ActiveRecord::Associations::Preloader` class
+ added owner record class name in order to simplify to find problem code.
+
+ *Paul Nikitochkin*
+
* `has_and_belongs_to_many` is now transparently implemented in terms of
`has_many :through`. Behavior should remain the same, if not, it is a bug.
@@ -153,13 +153,13 @@ def records_by_reflection(association, records)
records.group_by do |record|
reflection = record.class.reflect_on_association(association)
- reflection || raise_config_error(association)
+ reflection || raise_config_error(record, association)
end
end
- def raise_config_error(association)
+ def raise_config_error(record, association)
raise ActiveRecord::ConfigurationError,
- "Association named '#{association}' was not found; " \
+ "Association named '#{association}' was not found on #{record.class.name}; " \
"perhaps you misspelled it?"
end

0 comments on commit 625cd69

Please sign in to comment.