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

Handle uniqueness validation for translated attributes and translated scopes #28

Merged
merged 7 commits into from
May 5, 2017

Conversation

shioyama
Copy link
Owner

@shioyama shioyama commented May 5, 2017

This adds a Mobility::ActiveRecord::UniquenessValidator that is defined as a subclass on a model namespace when the model includes Mobility. By doing this, the model will use this validator if validates is called with uniqueness: true, but due to the namespacing the validator will not be used for any other (non-translated) models.

I'm conciously avoiding monkey-patching the original uniqueness validator since that could have strange and unpredictable results. The validator defined here sticks to very simple queries using where and not in order to be compatible with any supported backend.

Fixes #20

@shioyama shioyama force-pushed the uniqueness_validation branch from 285d7a0 to 354701e Compare May 5, 2017 12:50
@shioyama shioyama force-pushed the uniqueness_validation branch from 354701e to 2c35c8a Compare May 5, 2017 12:54
@shioyama shioyama merged commit 2c35c8a into master May 5, 2017
@shioyama shioyama deployed to github-pages May 5, 2017 13:46 Active
@shioyama shioyama deleted the uniqueness_validation branch May 5, 2017 13:48
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

Successfully merging this pull request may close these issues.

1 participant