diff options
Diffstat (limited to 'activerecord')
-rwxr-xr-x | activerecord/lib/active_record/associations.rb | 15 | ||||
-rw-r--r-- | activerecord/test/associations_go_eager_test.rb | 12 |
2 files changed, 23 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 419187015b..6f49800df6 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -739,13 +739,20 @@ module ActiveRecord end def find_with_associations(options = {}) - reflections = reflect_on_included_associations(options[:include]) + reflections = reflect_on_included_associations(options[:include]) + reflections.each do |r| + raise( + NoMethodError, + "Association was not found; perhaps you misspelled it? You specified :include=>:#{options[:include].join(', :')}" + ) if r.nil? + end + schema_abbreviations = generate_schema_abbreviations(reflections) primary_key_table = generate_primary_key_table(reflections, schema_abbreviations) - rows = select_all_rows(options, schema_abbreviations, reflections) - records, records_in_order = { }, [] - primary_key = primary_key_table[table_name] + rows = select_all_rows(options, schema_abbreviations, reflections) + records, records_in_order = { }, [] + primary_key = primary_key_table[table_name] for row in rows id = row[primary_key] diff --git a/activerecord/test/associations_go_eager_test.rb b/activerecord/test/associations_go_eager_test.rb index 29a0e8a443..110fb8e4ae 100644 --- a/activerecord/test/associations_go_eager_test.rb +++ b/activerecord/test/associations_go_eager_test.rb @@ -92,5 +92,17 @@ class EagerAssociationTest < Test::Unit::TestCase :conditions => ["companies.name = ?", "37signals"]) assert_not_nil companies(:first_firm, :reload).account end + + def test_eager_with_invalid_association_reference + assert_raises(NoMethodError, "Association was not found; perhaps you misspelled it? You specified :include=>:monkeys") { + post = Post.find(6, :include=>[ :monkeys ]) + } + assert_raises(NoMethodError, "Association was not found; perhaps you misspelled it? You specified :include=>:monkeys, :elephants") { + post = Post.find(6, :include=>[ :monkeys, :elephants ]) + } + end + end + + |