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

Ignore acts_as_paranoid default_scope in a particular method #172

Open
gamesover opened this issue Jul 22, 2020 · 3 comments
Open

Ignore acts_as_paranoid default_scope in a particular method #172

gamesover opened this issue Jul 22, 2020 · 3 comments

Comments

@gamesover
Copy link

gamesover commented Jul 22, 2020

After defining acts_as_paranoid for models, it will add default_scope not_deleted for the model.

Now, we have such a strange req., within one particular method, we hope to ignore acts_as_paranoid default not_deleted scope.

Also, we don't know what model/instance will be passed to this method since we are using metaprogramming for this method.

We do have a req, please ignore acts_as_paranoid in this method :)

I know it is very strange. Is it doable?

@mvz
Copy link
Contributor

mvz commented Jul 22, 2020

If you want to include both deleted and not-deleted items, you can use the with_deleted scope.

@gamesover
Copy link
Author

gamesover commented Jul 22, 2020

@mvz thanks for your hints.
Yes, I do know with_deleted.
However, it is metaprogramming, what instance/model/ruby code passed is out of my control. The model may or may not enable acts_as_paranoid. But as you mentioned, whatever passed to the method, must be with_deleted actually.

@mvz
Copy link
Contributor

mvz commented Jul 22, 2020

You can use respond_to? or similar to check if the passed-in model has the with_deleted scope.

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