Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

with_deleted scope #75

Open
stanley90 opened this issue Jul 9, 2024 · 4 comments
Open

with_deleted scope #75

stanley90 opened this issue Jul 9, 2024 · 4 comments

Comments

@stanley90
Copy link

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 mongodb/mongoid#5832)
Thanks

@simi
Copy link
Owner

simi commented Jul 9, 2024

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

@stanley90
Copy link
Author

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
Copy link
Owner

simi commented Jul 9, 2024

@stanley90 sounds good

@stanley90
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants