Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve exception message for HasManyThroughAssociationPolymorphicSource... #7569

Conversation

skorfmann
Copy link
Contributor

Exception message was misleading, as it is possible to have a
polymorphic 'has_many :through' join model.

@@ -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.singularize.camelcase}\"' to 'has_many :through' definition.")

Choose a reason for hiding this comment

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

Use the new hash style inside the message please.

Choose a reason for hiding this comment

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

Is this error only used when source_type is not present?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your feedback.

Choose a reason for hiding this comment

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

Ok. There's no need to change the other messages, it wouldn't be accepted I believe, just this one you're adding now. Thanks.

Choose a reason for hiding this comment

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

Also, wouldn't the message be to the 'has_many :through' definition, with the? (just wondering...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think, it is more like a recommendation than a question.

@carlosantoniodasilva
Copy link
Member

Please squash the commits into one. Thanks.

@skorfmann
Copy link
Contributor Author

@carlosantoniodasilva squashed the commits - wondering how the process proceeds from here.

@carlosantoniodasilva
Copy link
Member

@skorfmann thanks, now we merge :).

But something just came to my mind: shouldn't we be using classify instead of singularize.camelcase?

>> 'egg_and_hams'.camelcase
=> "EggAndHams"
>> 'egg_and_hams'.classify
=> "EggAndHam"

I think it can give us a more consistent output, wdyt?

@skorfmann
Copy link
Contributor Author

That is actually the method I was looking for but couldn't recall :) I will update the pull request tomorrow (it's getting late here in Australia)

Thanks

On 09.09.2012, at 23:33, Carlos Antonio da Silva notifications@github.com wrote:

@skorfmann thanks, now we merge :).

But something just came to my mind: shouldn't we be using classify instead of singularize.camelcase?

'egg_and_hams'.camelcase
=> "EggAndHams"
'egg_and_hams'.classify
=> "EggAndHam"
I think it can give us a more consistent output, wdyt?


Reply to this email directly or view it on GitHub.

@carlosantoniodasilva
Copy link
Member

Sure! Just ping me afterwards and I'll merge, thanks.

…rceError

Exception message was misleading, as it is possible to have a
polymorphic 'has_many :through' join model.
@skorfmann
Copy link
Contributor Author

@carlosantoniodasilva I guess i should have mentioned you in the last comment :)

@carlosantoniodasilva
Copy link
Member

Oh I missed it, thanks!

carlosantoniodasilva added a commit that referenced this pull request Sep 11, 2012
…ption-message

Improve exception message for HasManyThroughAssociationPolymorphicSourceError
@carlosantoniodasilva carlosantoniodasilva merged commit 8295663 into rails:master Sep 11, 2012
@skorfmann
Copy link
Contributor Author

No worries - Thanks for your support!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants