Respect new records for `CollectionProxy#uniq` #26980

Merged
merged 1 commit into from Nov 17, 2016

Projects

None yet

4 participants

@kamipo
Member
kamipo commented Nov 6, 2016 edited

Currently if CollectionProxy has more than one new record,
CollectionProxy#uniq result is incorrect.

And CollectionProxy#uniq was aliased to distinct in a1bb6c8.
But the uniq method and the SELECT DISTINCT method are different
methods. The doc in CollectionProxy is for the SELECT DISTINCT
method, not for the uniq method.

Therefore, reverting the alias in CollectionProxy to fix the
inconsistency and to have the both methods.

@sgrif sgrif was assigned by rails-bot Nov 6, 2016
@rails-bot

r? @sgrif

(@rails-bot has picked a reviewer for you, use r? to override)

@kamipo kamipo changed the title from Respect new records for `CollectionProxy#dictinct` to Respect new records for `CollectionProxy#distinct` Nov 6, 2016
@sgrif
Member
sgrif commented Nov 7, 2016

I would have expected this code to just do SELECT DISTINCT and not do it in memory.

@kamipo
Member
kamipo commented Nov 7, 2016

This method exists since the initial commit.
https://github.com/rails/rails/blob/db045dbbf60b53dbe013ef25554fd013baf88134/activerecord/lib/active_record/associations/association_collection.rb#L72-L74

SELECT DISTINCT method was added since v3.2.0.rc1.
562583c#diff-bf6dd6226db3aab589916f09236881c7R190

If we expects SELECT DISTINCT, should we remove the method? (CollectionProxy already have SELECT DISTINCT method because inherits Relation but overridden by the method)

@kamipo kamipo Respect new records for `CollectionProxy#uniq`
Currently if `CollectionProxy` has more than one new record,
`CollectionProxy#uniq` result is incorrect.

And `CollectionProxy#uniq` was aliased to `distinct` in a1bb6c8.
But the `uniq` method and the `SELECT DISTINCT` method are different
methods. The doc in `CollectionProxy` is for the `SELECT DISTINCT`
method, not for the `uniq` method.

Therefore, reverting the alias in `CollectionProxy` to fix the
inconsistency and to have the both methods.
0ec967a
@kamipo kamipo changed the title from Respect new records for `CollectionProxy#distinct` to Respect new records for `CollectionProxy#uniq` Nov 12, 2016
@sgrif sgrif merged commit 07af54d into rails:master Nov 17, 2016

2 checks passed

codeclimate Code Climate didn't find any new or fixed issues.
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@kamipo kamipo deleted the kamipo:respect_new_records_for_collection_proxy_distinct branch Nov 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment