Skip to content

Commit d6a39e9

Browse files
committed
Fix an incorrect example in safety section for Rails/Pluck
rubocop#826 reports an error on alias column, not on `alias_attribute`. In fact, `alias_attribute` doesn't seem to cause an error.
1 parent 1913c1d commit d6a39e9

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

lib/rubocop/cop/rails/pluck.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,15 @@ module Rails
1010
# results in a more efficient query that only selects the necessary key.
1111
#
1212
# @safety
13-
# This cop is unsafe because model can define attribute aliases.
13+
# This cop is unsafe because model can use column aliases.
1414
#
1515
# [source,ruby]
1616
# ----
17-
# class User < ApplicationRecord
18-
# alias_attribute :nickname, :name
19-
# end
20-
#
2117
# # Original code
22-
# User.map { |user| user[:nickname] } # => array of nicknames
18+
# User.select('name AS nickname').map { |user| user[:nickname] } # => array of nicknames
2319
#
2420
# # After autocorrection
25-
# User.pluck(:nickname) # => raises ActiveRecord::StatementInvalid
21+
# User.select('name AS nickname').pluck(:nickname) # => raises ActiveRecord::StatementInvalid
2622
# ----
2723
#
2824
# @example

0 commit comments

Comments
 (0)