Simplify SQL using DISTINCT
Using `pluck("DISTINCT")` was raising a warning in Rails 5.2:
DEPRECATION WARNING: Dangerous query method (method whose arguments are
used as raw SQL) called with non-attribute argument(s): "DISTINCT
taggings.tag_id". Non-attribute arguments will be disallowed in Rails
6.0. This method should not be called with user-provided values, such as
request parameters or model attributes. Known-safe values can be passed
by wrapping them in Arel.sql().
Since there was only one other use of distinct, I've decided to change
both of them in the same commit, even if the second one wasn't raising a
warning.
This commit is contained in:
@@ -46,10 +46,8 @@ class UserSegments
|
||||
def self.not_supported_on_current_budget
|
||||
author_ids(
|
||||
User.where(
|
||||
"id NOT IN (SELECT DISTINCT(voter_id) FROM votes"\
|
||||
" WHERE votable_type = ? AND votes.votable_id IN (?))",
|
||||
"Budget::Investment",
|
||||
current_budget_investments.pluck(:id)
|
||||
"id NOT IN (?)",
|
||||
Vote.select(:voter_id).where(votable: current_budget_investments).distinct
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user