-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
rename Relation#uniq
to Relation#distinct
#9683
rename Relation#uniq
to Relation#distinct
#9683
Conversation
@jonleighton @carlosantoniodasilva what do you think? |
@@ -651,9 +651,10 @@ def destroy(*records) | |||
# | |||
# person.pets.select(:name).uniq |
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.
Probably this doc should be also updated.
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.
@senny ^^ ping about this
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.
missed this one 😕 . Pushed an updated version.
Overall it looks good, just afraid that people could be using |
@carlosantoniodasilva we could alias it too... |
Seems good to me. I agree about aliasing |
@jonleighton I alias |
The similarity of `Relation#uniq` to `Array#uniq` is confusing. Since our Relation API is close to SQL terms I renamed `#uniq` to `#distinct`. There is no deprecation. `#uniq` and `#uniq!` are aliases and will continue to work. I also updated the documentation to promote the use of `#distinct`.
We moved more and more away from passing options to finder / calculation methods. The `:distinct` option in `#count` was one of the remaining places. Since we can now combine `Relation#distinct` with `Relation#count` the option is no longer necessary and can be deprecated.
rename `Relation#uniq` to `Relation#distinct`
👍 ❤️ |
this seems wrong, distinct is a parameter specifically to the count expression
is this supposed to be a replacement for the above?
this both reads wrong, and produces unintended (albeit innocuous in this case) sql:
|
|
so would |
The reason is to make the API consistent with our view of not passing options to finders/calculations methods. It is a matter of reducing the API possibilities to focus on what is important. This feature in my opinion doesn't add anything over |
That may be an argument for rejecting a feature request, but not for introducing a breaking change. |
In my opinion keeping the API consistent is worth a breaking change. There were also special cases where SELECT COUNT(DISTINCT(name, email)) FROM members; It's better to let the user know that he can specify the exact count clause than abstracting that away with the Member.count("DISTINCT(name, email)") Also the
Those two avenues provide a more complete API and there is no more need to keep the third option (passing |
Yes, it is an argument to introducing a breaking change too for two reasons:
|
1.
The similarity of
Relation#uniq
toArray#uniq
is confusing. Since ourRelation API is close to SQL terms I renamed
#uniq
to#distinct
.There is no deprecation.
#uniq
and#uniq!
are aliases and will continueto work. I also updated the documentation to promote the use of
#distinct
.c7f94f0
2.
Deprecate the
:distinct
option forRelation#count
.We moved more and more away from passing options to finder / calculation
methods. The
:distinct
option in#count
was one of the remaining places.Since we can now combine
Relation#distinct
withRelation#count
the optionis no longer necessary and can be deprecated.