From acc1f4f3902f4e8fdd8c5e1e1ccba1c74bfdbd88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thiago=20Figueir=C3=B3?= Date: Mon, 13 May 2024 10:58:16 +1000 Subject: [PATCH] Warn about subqueries when replacing pluck with pick --- lib/rubocop/cop/rails/pick.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/rubocop/cop/rails/pick.rb b/lib/rubocop/cop/rails/pick.rb index f4f344ff9c..c927fff2dd 100644 --- a/lib/rubocop/cop/rails/pick.rb +++ b/lib/rubocop/cop/rails/pick.rb @@ -9,6 +9,10 @@ module Rails # `pick` avoids. When called on an Active Record relation, `pick` adds a # limit to the query so that only one value is fetched from the database. # + # Note that when `pick` is added to a relation with an existing limit, it + # causes a subquery to be added. In most cases this is undesirable, and + # care should be taken while resolving this violation. + # # @safety # This cop is unsafe because `pluck` is defined on both `ActiveRecord::Relation` and `Enumerable`, # whereas `pick` is only defined on `ActiveRecord::Relation` in Rails 6.0. This was addressed