Skip to content

A platform for community discussion. Free, open, simple.

DEV: Remove with_deleted workarounds for old Rails version (#11550)

David Taylord25fd34b441d
diff --git a/app/models/concerns/trashable.rb b/app/models/concerns/trashable.rb
index 1caf0de7659..2a7e51fa81a 100644
--- a/app/models/concerns/trashable.rb
+++ b/app/models/concerns/trashable.rb
@@ -4,31 +4,12 @@ module Trashable
extend ActiveSupport::Concern
included do
- default_scope { where(with_deleted_scope_sql) }
+ default_scope { where(deleted_at: nil) }
+ scope :with_deleted, -> { unscope(where: :deleted_at) }
- # scope unscoped does not work
belongs_to :deleted_by, class_name: 'User'
end
- module ClassMethods
- def with_deleted
- # lifted from acts_as_paranoid, works around https://github.com/rails/rails/issues/4306
- #
- # with this in place Post.limit(10).with_deleted, will work as expected
- #
- scope = self.all
-
- # must use :send here cause predicates is protected
- # careful with updates of this API
- scope.where_clause.send(:predicates).delete(with_deleted_scope_sql)
- scope
- end
-
- def with_deleted_scope_sql
- all.table[:deleted_at].eq(nil).to_sql
- end
- end
-
def trashed?
deleted_at.present?
end
diff --git a/app/models/topic_tracking_state.rb b/app/models/topic_tracking_state.rb
index 9e24edab59f..69b983175bc 100644
--- a/app/models/topic_tracking_state.rb
+++ b/app/models/topic_tracking_state.rb
@@ -235,7 +235,7 @@ class TopicTrackingState
always: User::NewTopicDuration::ALWAYS,
default_duration: SiteSetting.default_other_new_topic_duration_minutes,
min_date: Time.at(SiteSetting.min_new_topics_time).to_datetime
- ).where_clause.send(:predicates)[0]
+ ).where_clause.ast.to_sql
end
def self.include_tags_in_report?
@@ -313,8 +313,7 @@ class TopicTrackingState
else
TopicQuery
.unread_filter(Topic, -999, staff: opts && opts[:staff])
- .where_clause.send(:predicates)
- .join(" AND ")
+ .where_clause.ast.to_sql
.gsub("-999", ":user_id")
end
@@ -329,7 +328,7 @@ class TopicTrackingState
if opts[:skip_new]
"1=0"
else
- TopicQuery.new_filter(Topic, "xxx").where_clause.send(:predicates).join(" AND ").gsub!("'xxx'", treat_as_new_topic_clause) +
+ TopicQuery.new_filter(Topic, "xxx").where_clause.ast.to_sql.gsub!("'xxx'", treat_as_new_topic_clause) +
" AND topics.created_at > :min_new_topic_date" +
" AND (category_users.last_seen_at IS NULL OR topics.created_at > category_users.last_seen_at)"
end
diff --git a/plugins/poll/app/models/poll.rb b/plugins/poll/app/models/poll.rb
index cbb3016f46b..b923caff99f 100644
--- a/plugins/poll/app/models/poll.rb
+++ b/plugins/poll/app/models/poll.rb
@@ -4,7 +4,7 @@ class Poll < ActiveRecord::Base
# because we want to use the 'type' column and don't want to use STI
self.inheritance_column = nil
- belongs_to :post, -> { unscope(:where) }
+ belongs_to :post, -> { with_deleted }
has_many :poll_options, -> { order(:id) }, dependent: :destroy
has_many :poll_votes