-
-
Notifications
You must be signed in to change notification settings - Fork 264
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
Refactor validates_uniqueness_to_tenant #242
Refactor validates_uniqueness_to_tenant #242
Conversation
9e7eae5
to
13eaaf8
Compare
13eaaf8
to
47d6f24
Compare
.where.not(id: instance.id).empty? | ||
errors.add(field, "has already been taken") | ||
end | ||
global_validation_args = args.merge(conditions: -> { where(fkey => nil) }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like this, because it discards conditions from args
, not sure how to merge lambdas here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only thing I could imagine working for that would be an array of lambdas?
64e60bf
to
f561199
Compare
f561199
to
18f764b
Compare
hi again @excid3 , I splitted validations to 3:
Also I've added calls for Also I think |
I think this sounds good. I haven't used any global models like this in an app so I'll have to refresh myself on it. Could any of these changes be breaking for existing users? |
I hope no
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, plz 🚢 it
Hi,
I refactored this validation method because it didn't work for global records with mobility. Queries used in
validates_uniqueness_to_tenant
didn't work with mobility's fields.But mobility overrides UniquenessValidator to validate translated fields.
I decided to use
validates_uniqueness_of
in the case of global model, becausevalidates_uniqueness_of
runs same query by itself.For global records:
in perfect world it should be done with 1 query validating
tenant = nil OR value
, but rails validations don't allow it.