Skip to content

Commit

Permalink
Improve exception message for HasManyThroughAssociationPolymorphicSou…
Browse files Browse the repository at this point in the history
…rceError

Exception message was misleading, as it is possible to have a
polymorphic 'has_many :through' join model.
  • Loading branch information
skorfmann committed Sep 9, 2012
1 parent f415475 commit 1e554a6
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/associations.rb
Expand Up @@ -17,7 +17,7 @@ def initialize(owner_class_name, reflection)


class HasManyThroughAssociationPolymorphicSourceError < ActiveRecordError #:nodoc: class HasManyThroughAssociationPolymorphicSourceError < ActiveRecordError #:nodoc:
def initialize(owner_class_name, reflection, source_reflection) 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
end end


Expand Down

5 comments on commit 1e554a6

@skorfmann
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... and classified

@pehlert
Copy link

@pehlert pehlert commented on 1e554a6 Nov 9, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@skorfmann
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link

@pehlert pehlert commented on 1e554a6 Nov 9, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Owner Author

@skorfmann skorfmann commented on 1e554a6 Nov 9, 2012 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.