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

Add delete_all to the list of methods that skip model validations #332

Open
etherbob opened this issue Dec 19, 2022 · 2 comments
Open

Add delete_all to the list of methods that skip model validations #332

etherbob opened this issue Dec 19, 2022 · 2 comments

Comments

@etherbob
Copy link

Is your feature request related to a problem? Please describe.

We were recently burned by a scenario where we were calling delete on some models and/or delete_all on some associations and bypassing various callbacks before_destroys etc.

Describe the solution you'd like

I'm thinking it'd be nice to have delete, and delete_all added to the list for https://rails.rubystyle.guide/#beware-skip-model-validations

Describe alternatives you've considered

I could see a distinct rule of preferring destroy and destroy_all over delete/delete_all being a preferred alternative since really it's about before_destroy callbacks (and/or setting updated_at if you use something like acts_as_paranoid) vs hitting the actual model validations

Additional context

Sorry if this is a little thin. Given a bit more time (and assuming it's wanted) I'll take a swing at the alternative option and submit it as a PR.

@andyw8
Copy link
Contributor

andyw8 commented Dec 20, 2022

I agree, both should be added.

@koic
Copy link
Member

koic commented Mar 29, 2023

Beware of the behavior of the following methods.

Can you try to open a PR to the Rails Guides, which is the link to the above Rails Style Guide, first?
https://guides.rubyonrails.org/active_record_validations.html#skipping-validations

Once added to that, it could then be added to the Style Guide. Eventually it will be reflected in the style guide implementation Rails/SkipsModelValidations.

@koic koic transferred this issue from rubocop/rubocop-rails Mar 29, 2023
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

3 participants