Permalink
Browse files

Nicer error message on has_many :through when :through reflection can…

… not be found (closes #4042) [court3nay@gmail.com]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3910 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 9bd7db4 commit df97ed5e4c986be875248ec1b27d7acfc200ae9c @dhh dhh committed Mar 18, 2006
View
@@ -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]
@@ -61,7 +61,9 @@ def find_target
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 =
@@ -207,6 +207,10 @@ def test_belongs_to_polymorphic_with_counter_cache
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)
@@ -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

0 comments on commit df97ed5

Please sign in to comment.