From 596ef8d1ed1ef69f0a8da169b0afa5117b28f43f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Thu, 17 Jan 2019 20:11:11 +0100 Subject: [PATCH] Fix queries and scopes after column deletion Some queries were accessing original column instead of the new translatable one. This should have been causing unexpected behavior for requests maded in a different locale than the application default. --- app/controllers/admin/poll/polls_controller.rb | 1 + app/controllers/budgets/executions_controller.rb | 2 +- app/controllers/polls_controller.rb | 2 +- app/models/budget/investment.rb | 2 +- app/models/poll.rb | 2 +- app/models/poll/booth.rb | 2 +- 6 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/controllers/admin/poll/polls_controller.rb b/app/controllers/admin/poll/polls_controller.rb index 04a94cce3..90cf751a1 100644 --- a/app/controllers/admin/poll/polls_controller.rb +++ b/app/controllers/admin/poll/polls_controller.rb @@ -67,6 +67,7 @@ class Admin::Poll::PollsController < Admin::Poll::BaseController end def poll_params + image_attributes = [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy] attributes = [:name, :starts_at, :ends_at, :geozone_restricted, :results_enabled, :stats_enabled, :budget_id, geozone_ids: [], image_attributes: image_attributes] diff --git a/app/controllers/budgets/executions_controller.rb b/app/controllers/budgets/executions_controller.rb index 54decebee..0d4c25134 100644 --- a/app/controllers/budgets/executions_controller.rb +++ b/app/controllers/budgets/executions_controller.rb @@ -19,7 +19,7 @@ module Budgets .group_by(&:heading) else @budget.investments.winners - .joins(:milestones).includes(:milestones) + .joins(milestones: :translations) .distinct.group_by(&:heading) end end diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 652a9eaae..5fab93a0f 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -11,7 +11,7 @@ class PollsController < ApplicationController ::Poll::Answer # trigger autoload def index - @polls = @polls.not_budget.send(@current_filter).includes(:geozones).sort_for_list.page(params[:page]) + @polls = @polls.not_budget.send(@current_filter).sort_for_list.page(params[:page]) end def show diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index 37d202c56..c3842dc94 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -368,7 +368,7 @@ class Budget end def self.with_milestone_status_id(status_id) - joins(:milestones).includes(:milestones).select do |investment| + includes(milestones: :translations).select do |investment| investment.milestone_status_id == status_id.to_i end end diff --git a/app/models/poll.rb b/app/models/poll.rb index 012fce912..e90bf191b 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -37,7 +37,7 @@ class Poll < ActiveRecord::Base scope :public_for_api, -> { all } scope :not_budget, -> { where(budget_id: nil) } - scope :sort_for_list, -> { order(:geozone_restricted, :starts_at, :name) } + scope :sort_for_list, -> { joins(:translations).order(:geozone_restricted, :starts_at, "poll_translations.name") } def title name diff --git a/app/models/poll/booth.rb b/app/models/poll/booth.rb index e794a0190..5dfd32a6f 100644 --- a/app/models/poll/booth.rb +++ b/app/models/poll/booth.rb @@ -12,7 +12,7 @@ class Poll end def self.available - where(polls: { id: Poll.current_or_recounting }).includes(:polls) + where(polls: { id: Poll.current_or_recounting }).joins(polls: :translations) end def assignment_on_poll(poll)