Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove to_s from Arel.sql statements #12650

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion decidim-core/app/models/decidim/user.rb
Expand Up @@ -63,7 +63,7 @@ def self.all
actual_ids = scope_ids.select(&:presence)
if actual_ids.count.positive?
ids = actual_ids.map(&:to_i).join(",")
where(Arel.sql("extended_data->'interested_scopes' @> ANY('{#{ids}}')").to_s)
where(Arel.sql("extended_data->'interested_scopes' @> ANY('{#{ids}}')"))
else
# Do not apply the scope filter when there are scope ids available. Note
# that the active record scope must always return an active record
Expand Down
12 changes: 6 additions & 6 deletions decidim-core/app/queries/decidim/last_activity.rb
Expand Up @@ -60,14 +60,14 @@ def filter_spaces(query)
"decidim_action_logs.participatory_space_type = '#{manifest.model_class_name}'",
"decidim_action_logs.participatory_space_id IN (#{Arel.sql(klass.visible_for(current_user).select(:id).to_sql)})"
].join(" AND ")
).to_s
)
else
Arel.sql("decidim_action_logs.participatory_space_type = '#{manifest.model_class_name}'").to_s
Arel.sql("decidim_action_logs.participatory_space_type = '#{manifest.model_class_name}'")
end

conditions << "(#{condition})"
end
query.where(Arel.sql(conditions.join(" OR ")).to_s)
query.where(Arel.sql(conditions.join(" OR ")))
end

def filter_deleted(query)
Expand All @@ -82,15 +82,15 @@ def filter_deleted(query)
"decidim_action_logs.resource_type = '#{resource_type}'",
"decidim_action_logs.resource_id IN (#{Arel.sql(klass.not_deleted.select(:id).to_sql)})"
].join(" AND ")
).to_s
)
else
Arel.sql("decidim_action_logs.resource_type = '#{resource_type}'").to_s
Arel.sql("decidim_action_logs.resource_type = '#{resource_type}'")
end

conditions << "(#{condition})"
end

query.where(Arel.sql(conditions.join(" OR ")).to_s)
query.where(Arel.sql(conditions.join(" OR ")))
end
end
end
2 changes: 1 addition & 1 deletion decidim-core/app/resolvers/decidim/core/metric_resolver.rb
Expand Up @@ -56,7 +56,7 @@ def filter
def group
@records = @records
.group(group_by)
.order(Arel.sql("#{group_by} DESC").to_s)
.order(Arel.sql("#{group_by} DESC"))
end

def sum
Expand Down
2 changes: 1 addition & 1 deletion decidim-core/lib/decidim/scopable.rb
Expand Up @@ -39,7 +39,7 @@ module Scopable
conditions << "#{table_name}.decidim_scope_id IS NULL" if clean_scope_ids.delete("global")
conditions.concat(["? = ANY(decidim_scopes.part_of)"] * clean_scope_ids.count) if clean_scope_ids.any?

includes(:scope).references(:decidim_scopes).where(Arel.sql(conditions.join(" OR ")).to_s, *clean_scope_ids.map(&:to_i))
includes(:scope).references(:decidim_scopes).where(Arel.sql(conditions.join(" OR ")), *clean_scope_ids.map(&:to_i))
}
end

Expand Down
4 changes: 2 additions & 2 deletions decidim-core/lib/decidim/searchable.rb
Expand Up @@ -162,8 +162,8 @@ def order_by_id_list(id_list)
return ApplicationRecord.none if id_list.to_a.empty?

values_clause = id_list.each_with_index.map { |id, i| "(#{id}, #{i})" }.join(", ")
joins(Arel.sql("JOIN (VALUES #{values_clause}) AS #{table_name}_id_order(id, ordering) ON #{table_name}.id = #{table_name}_id_order.id").to_s)
.order(Arel.sql("#{table_name}_id_order.ordering").to_s)
joins(Arel.sql("JOIN (VALUES #{values_clause}) AS #{table_name}_id_order(id, ordering) ON #{table_name}.id = #{table_name}_id_order.id"))
.order(Arel.sql("#{table_name}_id_order.ordering"))
end

# Declares the searchable fields for this instance and, optionally, some conditions.
Expand Down
Expand Up @@ -30,7 +30,7 @@ def query
.published
.where(organization: @organization)
.where(
Arel.sql("GREATEST(#{title_similarity}, #{description_similarity}) >= ?").to_s,
Arel.sql("GREATEST(#{title_similarity}, #{description_similarity}) >= ?"),
translated_attribute(form.title),
translated_attribute(form.description),
Decidim::Initiatives.similarity_threshold
Expand Down
4 changes: 2 additions & 2 deletions decidim-proposals/app/models/decidim/proposals/proposal.rb
Expand Up @@ -120,11 +120,11 @@ def assign_state(token)
}

scope :sort_by_valuation_assignments_count_asc, lambda {
order(Arel.sql("#{sort_by_valuation_assignments_count_nulls_last_query} ASC NULLS FIRST").to_s)
order(Arel.sql("#{sort_by_valuation_assignments_count_nulls_last_query} ASC NULLS FIRST"))
}

scope :sort_by_valuation_assignments_count_desc, lambda {
order(Arel.sql("#{sort_by_valuation_assignments_count_nulls_last_query} DESC NULLS LAST").to_s)
order(Arel.sql("#{sort_by_valuation_assignments_count_nulls_last_query} DESC NULLS LAST"))
}

scope :state_eq, lambda { |state|
Expand Down