In model i have
def events_ids
result = volunteer_roles.uniq.pluck(:event_id)
result.any? ? result : nil
end
rubocop -a returns
Offenses:
app/models/user.rb:157:47: C: [Corrected] Use uniq before pluck
result = volunteer_roles.pluck(:event_id).uniq
^^^^
And in this case, it is wrong correction, because uniq or distinct methods return Array and pluck need Activerecord::Relation
@tjwp?
I cannot replay it now, but as I see it is closed :+1:
This is not fixed and should be reopened.
See: https://github.com/bbatsov/rubocop/issues/3122#issuecomment-218126545
I agree. It's not fixed.
I don't think we can easily distinguish between uniq being called on CollectionProxy vs an ActiveRecord::Relation :(
I should either:
uniq or distinct on associations.Let me know what is preferred in situations like this.
Maybe we can still "save" this cop by making it more conservative. I mean, we could start with some simple expressions that we believe will not generate many false positives. For example:
MyModel.pluck(:col).uniq
where the receiver looks like a class. We let the cop only report such expressions.
But even so, removing (or disabling) auto-correct might be necessary.
Most helpful comment
I don't think we can easily distinguish between
uniqbeing called onCollectionProxyvs anActiveRecord::Relation:(I should either:
uniqordistincton associations.Let me know what is preferred in situations like this.