aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activerecord/CHANGELOG2
-rw-r--r--activerecord/lib/active_record/associations/has_many_through_association.rb4
-rw-r--r--activerecord/test/associations_join_model_test.rb4
-rw-r--r--activerecord/test/fixtures/author.rb2
4 files changed, 11 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index d683e7642e..f7d9fb2f9f 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -47,6 +47,8 @@
has_many :attachments, :as => :attachable, :dependent => :delete_all
end
+* Nicer error message on has_many :through when :through reflection can not be found. #4042 [court3nay@gmail.com]
+
* Upgrade to Transaction::Simple 1.3 [Jamis Buck]
* Catch FixtureClassNotFound when using instantiated fixtures on a fixture that has no ActiveRecord model [Rick Olson]
diff --git a/activerecord/lib/active_record/associations/has_many_through_association.rb b/activerecord/lib/active_record/associations/has_many_through_association.rb
index 009ac7c53a..e242b9f7a1 100644
--- a/activerecord/lib/active_record/associations/has_many_through_association.rb
+++ b/activerecord/lib/active_record/associations/has_many_through_association.rb
@@ -61,7 +61,9 @@ module ActiveRecord
end
def construct_conditions
- through_reflection = @owner.class.reflections[@reflection.options[:through]]
+ unless through_reflection = @owner.class.reflections[@reflection.options[:through]]
+ raise ActiveRecordError, "Could not find the association '#{@reflection.options[:through]}' in model #{@reflection.klass}"
+ end
if through_reflection.options[:as]
conditions =
diff --git a/activerecord/test/associations_join_model_test.rb b/activerecord/test/associations_join_model_test.rb
index 58208ced65..7395aa5739 100644
--- a/activerecord/test/associations_join_model_test.rb
+++ b/activerecord/test/associations_join_model_test.rb
@@ -207,6 +207,10 @@ class AssociationsJoinModelTest < Test::Unit::TestCase
assert posts(:welcome, :reload)[:taggings_count].zero?
end
+ def test_unavailable_through_reflection
+ assert_raises (ActiveRecord::ActiveRecordError) { authors(:david).nothings }
+ end
+
private
# create dynamic Post models to allow different dependency options
def find_post_with_dependency(post_id, association, association_name, dependency)
diff --git a/activerecord/test/fixtures/author.rb b/activerecord/test/fixtures/author.rb
index 8c6cee51e4..0f0d1b12d9 100644
--- a/activerecord/test/fixtures/author.rb
+++ b/activerecord/test/fixtures/author.rb
@@ -22,6 +22,8 @@ class Author < ActiveRecord::Base
has_many :categorizations
has_many :categories, :through => :categorizations
+
+ has_many :nothings, :through => :kateggorisatons, :class_name => 'Category'
attr_accessor :post_log