From 251a5d4508216d6c0927577333abb502d93e408d Mon Sep 17 00:00:00 2001 From: Nicholas Seckar Date: Sun, 18 Sep 2005 20:41:44 +0000 Subject: Fix eager loading error messages, allow :include to specify tables using strings or symbols. Closes #2222 git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2258 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/CHANGELOG | 2 ++ activerecord/lib/active_record/associations.rb | 5 +++-- activerecord/test/associations_go_eager_test.rb | 10 ++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index 96b6f506b2..ec101186ea 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Fix eager loading error messages, allow :include to specify tables using strings or symbols. Closes #2222 [Marcel Molina] + * Added check for RAILS_CONNECTION_ADAPTERS on startup and only load the connection adapters specified within if its present (available in Rails through config.connection_adapters using the new config) #1958 [skae] * Fixed various problems with has_and_belongs_to_many when using customer finder_sql #2094 [Florian Weber] diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index bfa932c5b8..23ccb34cd2 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -782,14 +782,15 @@ module ActiveRecord def reflect_on_included_associations(associations) - [ associations ].flatten.collect { |association| reflect_on_association(association) } + [ associations ].flatten.collect { |association| reflect_on_association(association.to_s.intern) } end def guard_against_missing_reflections(reflections, options) reflections.each do |r| raise( ConfigurationError, - "Association was not found; perhaps you misspelled it? You specified :include => :#{options[:include].join(', :')}" + "Association was not found; perhaps you misspelled it? " + + "You specified :include => :#{[options[:include]].flatten.join(', :')}" ) if r.nil? end end diff --git a/activerecord/test/associations_go_eager_test.rb b/activerecord/test/associations_go_eager_test.rb index cd3f0e1f4a..750e8bd208 100644 --- a/activerecord/test/associations_go_eager_test.rb +++ b/activerecord/test/associations_go_eager_test.rb @@ -136,12 +136,22 @@ class EagerAssociationTest < Test::Unit::TestCase end def test_eager_with_invalid_association_reference + assert_raises(ActiveRecord::ConfigurationError, "Association was not found; perhaps you misspelled it? You specified :include => :monkeys") { + post = Post.find(6, :include=> :monkeys ) + } assert_raises(ActiveRecord::ConfigurationError, "Association was not found; perhaps you misspelled it? You specified :include => :monkeys") { post = Post.find(6, :include=>[ :monkeys ]) } + assert_raises(ActiveRecord::ConfigurationError, "Association was not found; perhaps you misspelled it? You specified :include => :monkeys") { + post = Post.find(6, :include=>[ 'monkeys' ]) + } assert_raises(ActiveRecord::ConfigurationError, "Association was not found; perhaps you misspelled it? You specified :include => :monkeys, :elephants") { post = Post.find(6, :include=>[ :monkeys, :elephants ]) } end + def test_eager_with_valid_association_as_string_not_symbol + assert_nothing_raised { Post.find(:all, :include => 'comments') } + end + end -- cgit v1.2.3