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

Does not normalize when validations are skipped #88

Closed
nathansamson opened this issue Apr 5, 2015 · 1 comment
Closed

Does not normalize when validations are skipped #88

nathansamson opened this issue Apr 5, 2015 · 1 comment

Comments

@nathansamson
Copy link

This might be a uncommon use case, but I have an import function (via excel/csv sheets).

If the object (lets call it ContactPerson) is not valid (eg misses fields etc...) I want to be able to use contact_person.save(validate: false), but if it contains a mobile number still have it normalized.

This is currently not the case.

Note that I probably should override my presence validators when importing, instead of skipping ALL validations, but still I find it unexpected that phony_normalize runs before_validation, instead of before_save, or even on the setter.

Although I am not sure what I expect it to do when the number can not be normalized (eg, is invalid)...

My current proposal is
A) normalize the number in before_save
B1) if the number is not valid, just store the value as if (if validations are skipped)
B2) if the number is valid just store the normalization.

This is the most backwards compatible, without breaking most existing expectations. Although it isn't really the least suprise either.

My main concern is that when not running validations, numbers are not normalized which ruins my search methods....

Hoping this makes a little sense, as I am quite confused myself :)

@joost
Copy link
Owner

joost commented Apr 13, 2015

Special cast. Just write your own before_filter that uses PhonyRails.normalize.
Otherwise please submit a pull request.

@joost joost closed this as completed Apr 13, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants