simi / mongoid_paranoia

Paranoid Documents for Mongoid 7
MIT License
121 stars 60 forks source link

with_deleted scope #75

Open stanley90 opened 3 months ago

stanley90 commented 3 months ago

Hi, I needed to have an option to remove the paranoia condition from an already-chained query (so can't use unscoped anymore), so I added the following scope: scope :with_deleted, -> { criteria.remove_scoping(base.unscoped.where(deleted_at: nil)) } Would you consider including it in Paranoia? (note: it depends on this https://github.com/mongodb/mongoid/pull/5832) Thanks

simi commented 3 months ago

Feel free to open PR. Just wondering how to detect related feature is present, using Mongoid version check?

stanley90 commented 3 months ago

In my app I patched Mongoid::Scopable::ClassMethods to add the feature until I upgrade Mongoid (I'm at 7.5). To be safe, I can check for Mongoid::Config.respond_to?(:allow_scopes_to_unset_default_scope) and only then define the scope (the desired behavior might be default since Mongoid 10, but that will take some time). Would that be acceptable? I can open a PR this week.

simi commented 3 months ago

@stanley90 sounds good

stanley90 commented 3 months ago

Actually need to wait until next Mongoid 9 release. Will come back.