From 0f8a3bdb082f9f5928ed2665cadcd98ac5ceab5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Prod=27homme?= Date: Thu, 21 Mar 2024 01:54:13 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20Add=20Yard=20documentation=20for?= =?UTF-8?q?=20Paranoia::Query=20(#555)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/paranoia.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/paranoia.rb b/lib/paranoia.rb index 7024c83c..b69b4402 100644 --- a/lib/paranoia.rb +++ b/lib/paranoia.rb @@ -24,6 +24,7 @@ def self.included(klazz) module Query def paranoid? ; true ; end + # If you want to find all records, even those which are deleted def with_deleted if ActiveRecord::VERSION::STRING >= "4.1" return unscope where: paranoia_column @@ -31,6 +32,7 @@ def with_deleted all.tap { |x| x.default_scoped = false } end + # If you want to find only the deleted records def only_deleted if paranoia_sentinel_value.nil? return with_deleted.where.not(paranoia_column => paranoia_sentinel_value) @@ -45,6 +47,7 @@ def only_deleted end alias_method :deleted, :only_deleted + # If you want to restore a record def restore(id_or_ids, opts = {}) ids = Array(id_or_ids).flatten any_object_instead_of_id = ids.any? { |id| ActiveRecord::Base === id }