diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-09-20 11:52:10 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-09-20 11:52:10 -0700 |
commit | 8f9bba7058c5ff376c7fbcd0f2d5561758085b8e (patch) | |
tree | 7bfe2027093453fbee8e4ff81777019c44f51308 | |
parent | 7ad26e8a45c2c04a5b9adfa9fb4979d906771f5b (diff) | |
download | rails-8f9bba7058c5ff376c7fbcd0f2d5561758085b8e.tar.gz rails-8f9bba7058c5ff376c7fbcd0f2d5561758085b8e.tar.bz2 rails-8f9bba7058c5ff376c7fbcd0f2d5561758085b8e.zip |
extract exception raising, clean up group_by statement
-rw-r--r-- | activerecord/lib/active_record/associations/preloader.rb | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/associations/preloader.rb b/activerecord/lib/active_record/associations/preloader.rb index fd294051d4..6732a5eb8d 100644 --- a/activerecord/lib/active_record/associations/preloader.rb +++ b/activerecord/lib/active_record/associations/preloader.rb @@ -147,15 +147,16 @@ module ActiveRecord records.group_by do |record| reflection = record.class.reflect_on_association(association) - unless reflection - raise ActiveRecord::ConfigurationError, "Association named '#{association}' was not found; " \ - "perhaps you misspelled it?" - end - - reflection + reflection || raise_config_error(association) end end + def raise_config_error(association) + raise ActiveRecord::ConfigurationError, + "Association named '#{association}' was not found; " \ + "perhaps you misspelled it?" + end + def association_klass(reflection, record) if reflection.macro == :belongs_to && reflection.options[:polymorphic] klass = record.send(reflection.foreign_type) |