Skip to content
New issue

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

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

Already on GitHub? # to your account

Change how validate_uniqueness_of query works #368

Closed
paulcsmith opened this issue May 15, 2020 · 3 comments · Fixed by #701
Closed

Change how validate_uniqueness_of query works #368

paulcsmith opened this issue May 15, 2020 · 3 comments · Fixed by #701

Comments

@paulcsmith
Copy link
Member

paulcsmith commented May 15, 2020

See https://gitter.im/luckyframework/Lobby?at=5ebdf71bf3ce603074bc908a for some background on the issue

So it uses a query and doesn't end with a criteria. When I originally wrote this I didn't know how else to do it. But I figured out a better way to do it in AvramSlugify.

Now

validate_uniqueness_of name, query: UserQuery.new.project_id(1).name # Need to end with `name` criteria

After

validate_uniqueness_of name, query: UserQuery.new.project_id(1) # Just use a query

Do this by using the passed in attribute's name and a raw where. Still (mostly) type-safe because the attribute is typed and auto-generated by the model

@matthewmcgarvey
Copy link
Member

Switching to this style would remove the ability to change how the value is searched by. If you wanted to check for the uniqueness of a string case insensitively you can do validate_uniqueness_of name, query: UserQuery.new.name.lower currently. We could add additional parameters for certain column types to compare in different ways though String might be the only one that needs it.

@paulcsmith
Copy link
Member Author

That’s a good point. Maybe we allow either one? So you can return a criteria if you want to customize but it is not required. What do you think?

@matthewmcgarvey
Copy link
Member

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants