Today I learned how to bypass default_scope
using ActiveRecord::QueryMethods#unscope. And change a previously set where
condition.
class Products
default_scope where(enabled: true)
scope :disabled, -> { unscope(enabled: false) }
end
Another helpful method is ActiveRecord::QueryMethods#rewhere
class Products
default_scope where(enabled: true)
end
product = Products.first
product.rewhere(enabled: false)