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

* DEV: Remove with_deleted workarounds for old Rails version

These workarounds using private APIs are no longer required in the latest version of Rails. The referenced issue (https://github.com/rails/rails/issues/4306) was closed in 2013. The acts_as_paranoid workaround which this was based on was removed for rails > 5.

Switching to using a scope also allows us to use it within a `belongs_to` relation (e.g. in the Poll model). This avoids issues which can be caused by unscoping all `where` clauses.

Predicates are not necessarily strings, so calling `.join(" AND ")` can sometimes cause weird errors. If we use `WhereClause#ast`, and then `.to_sql` we achieve the same thing with fully public APIs, and it will work successfully for all predicates.
This commit is contained in:
David Taylor
2020-12-21 23:38:59 +00:00
committed by GitHub
parent 32e7ee4867
commit d25fd34b44
3 changed files with 6 additions and 26 deletions

View File

@@ -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