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

Rethink default scopes #480

Open
nymous opened this issue Jan 19, 2025 · 0 comments
Open

Rethink default scopes #480

nymous opened this issue Jan 19, 2025 · 0 comments

Comments

@nymous
Copy link
Member

nymous commented Jan 19, 2025

Not sure about our use of the default_scope in app/models/article.rb, app/models/payment_method.rb, app/models/subscription_offer.rb. It sure is easier to query later, however it also has some unexpected effects as it changes a new Article to set deleted_at: nil by default (though in this case this is the value we expect).
It can also be hard to cancel or override correctly, for example Article.first.refunds.unscoped will remove the WHERE refunds.article_id = $article_id constraint and show you all refunds, Article.first.unscoped.refunds doesn't change anything compared to without unscoped, and the correct thing is Article.unscoped.first.refunds. Also if you do Article.where(name: 'Câble').unscoped, the where clause is removed because unscoped removes everything before it.

For now it doesn't seem to cause any issue for us, so your call.

More reading:

(Taken from #467 (comment))

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

1 participant