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

Clarify the note about default_scope #104

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,14 @@ In both of these cases restoring either of these records will do right thing!

#### Default scope

It's usually undesirable to add a default scope. It will take more effort to
work around and will cause more headaches. If you know you need a default scope, it's easy to add yourself ❤.
Active Record Default scopes can be confusing - because they're magically injected by default - and
much has been written about avoiding them. There's even a Rubocop Rails::DefaultScope that automates
that advice. For these reasons, discard does not automatically set a default scope to only see undiscarded
rows.

However, many developers will find a default scope to be exactly what they want, because it will
follow the Principle of Least Surprise when coming from a codebase that does hard deletes. If desired, it
takes just one line of code to set the default scope as shown here:

``` ruby
class Post < ActiveRecord::Base
Expand Down