Permalink
Browse files

Improve exception message for HasManyThroughAssociationPolymorphicSou…

…rceError

Exception message was misleading, as it is possible to have a
polymorphic 'has_many :through' join model.
  • Loading branch information...
skorfmann committed Sep 7, 2012
1 parent f415475 commit 1e554a6011c3603b509ac0d83bf81c866053bb49
Showing with 1 addition and 1 deletion.
  1. +1 −1 activerecord/lib/active_record/associations.rb
@@ -17,7 +17,7 @@ def initialize(owner_class_name, reflection)
class HasManyThroughAssociationPolymorphicSourceError < ActiveRecordError #:nodoc:
def initialize(owner_class_name, reflection, source_reflection)
- super("Cannot have a has_many :through association '#{owner_class_name}##{reflection.name}' on the polymorphic object '#{source_reflection.class_name}##{source_reflection.name}'.")
+ super("Cannot have a has_many :through association '#{owner_class_name}##{reflection.name}' on the polymorphic object '#{source_reflection.class_name}##{source_reflection.name}' without 'source_type'. Try adding 'source_type: \"#{reflection.name.to_s.classify}\"' to 'has_many :through' definition.")
end
end

5 comments on commit 1e554a6

@skorfmann

This comment has been minimized.

Show comment
Hide comment
@skorfmann

skorfmann Sep 9, 2012

Owner

... and classified

Owner

skorfmann replied Sep 9, 2012

... and classified

@pehlert

This comment has been minimized.

Show comment
Hide comment
@pehlert

pehlert Nov 9, 2012

+1, this would have saved me lots of time today!

+1, this would have saved me lots of time today!

@skorfmann

This comment has been minimized.

Show comment
Hide comment
@skorfmann

skorfmann Nov 9, 2012

Owner

this is merged into rails master - but I'm not sure, if there was a release since it was merged.

https://github.com/rails/rails/blob/master/activerecord/lib/active_record/associations.rb#L23

Owner

skorfmann replied Nov 9, 2012

this is merged into rails master - but I'm not sure, if there was a release since it was merged.

https://github.com/rails/rails/blob/master/activerecord/lib/active_record/associations.rb#L23

@pehlert

This comment has been minimized.

Show comment
Hide comment
@pehlert

pehlert Nov 9, 2012

Sorry, I didn't even realize this was a forked repo. Guess I need a break. Many thanks for the information and your patch.

Sorry, I didn't even realize this was a forked repo. Guess I need a break. Many thanks for the information and your patch.

@skorfmann

This comment has been minimized.

Show comment
Hide comment
@skorfmann

skorfmann Nov 9, 2012

Owner
Owner

skorfmann replied Nov 9, 2012

Please sign in to comment.