Identifies multiple uses of ActiveRecord query selectmethod
While calling select multiple times on the same relation may technically be redundant, this is a completely distinct method from Array.select, and thus suggesting to use select! (which does not exist), should not happen.
Steps to reproduce the problem
Run rubocop on this file with Performance/ChainArrayAllocation enabled
models/test.rb
class Test < ActiveRecord::Base
scope :test_scope, -> {
select(:field_one, :field_two).
select("COUNT(DISTINCT(tests.field_three)) AS num").
where("tests.field_one IS NOT NULL").
group(:field_two)
}
def self.something
Test.all
.select(:field_one, :field_two)
.select("COUNT(DISTINCT(tests.field_three)) AS num")
.where("tests.field_one IS NOT NULL")
.group(:field_two)
end
end
Expected behavior
RuboCop suggests valid corrections on arrays.
Actual behavior
Identifies multiple uses of ActiveRecord query
select
method While callingselect
multiple times on the same relation may technically be redundant, this is a completely distinct method fromArray.select
, and thus suggesting to useselect!
(which does not exist), should not happen.Steps to reproduce the problem
Run rubocop on this file with
Performance/ChainArrayAllocation
enabledmodels/test.rb
RuboCop version
Found on version
Still occurs on latest
Perhaps this is why this cop is disabled by default, because it has these are unsolvable false positives?