Mongoid::Paranoia adds a default scope to the model which generates the criteria
#<Mongoid::Criteria
selector: {:deleted_at=>{"$exists"=>false}},
options: {},
class: Line,
embedded: false>
I can find deleted documents with Model.deleted which generates,
#<Mongoid::Criteria
selector: {:deleted_at=>{"$exists"=>true}},
options: {},
class: Line,
embedded: false>
How can i override this so i can search both deleted and non-deleted documents.
PS Model.unscoped
does not work
Try this(its kind of hack):
class User
include Mongoid::Document
include Mongoid::Paranoia
def self.ignore_paranoia
all.tap {|criteria| criteria.selector.delete(:deleted_at)}
end
end
# ignore paranoia is defined on model, so can't chain it to criteria or scopes
# but it returns criteria, so can chain other scope and criteria to it
User.ignore_paranoia.some_scope.where(:whatever => "my_custom_value")
I've taken to using:
def self.all!
Mongoid::Criteria.new self
end
but self.unscoped seems to work too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With