You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
…ocation`
Fixesrubocop#437.
This PR fixes a false positive for `Performance/ChainArrayAllocation`
when using `select` with block argument after `select`.
…ocation`
Fixesrubocop#437.
This PR fixes a false positive for `Performance/ChainArrayAllocation`
when using `select` with block argument after `select`.
Expected behavior
RuboCop suggests valid corrections on arrays.
Actual behavior
Identifies multiple uses of ActiveRecord query
select
methodWhile calling
select
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?
The text was updated successfully, but these errors were encountered: