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

Default scope is not that nice #62

Open
jiri1337 opened this issue Jan 22, 2025 · 1 comment
Open

Default scope is not that nice #62

jiri1337 opened this issue Jan 22, 2025 · 1 comment

Comments

@jiri1337
Copy link

We have many models and where we want to introduce hoardable to. The issue is that the default_scope is overriding already existing logic.

eg. Suddenly, this works differently

# includes versions now as well
user.documents 
document.attachments
attachment.variants
...

We have close to 100 models, and going through all relations like this and adjusting it is not feasible plus it is very hard to catch in tests as versions will only appear if there has been an update to the record.
There will be a forgotten relation somewhere that will break stuff that we won't catch therefore we currently are unable to.

Could you suggest or implement a nicer way to handle this? It is currently very difficult to bring hoardable to ongoing projects.

@waymondo
Copy link
Owner

waymondo commented Jan 23, 2025

unfortunately I don't anticipate changing the behavior of using default_scope to inject hoardable's ability to exclude versions in the near future. there isn't another self-evident Rails-y way to add scoping to all queries generated for a model that i'm aware of. if anyone else has ideas, i'm very open to them.

generally, i've found the usage of default_scope in application business logic to be an anti-pattern. my hope in using default_scope in hoardable was that it would be unused and available for establishing the base control over the table inheritance querying.

my suggestion would be to either remove the application's usage of default_scope for those models, or add hoardable's exclude_versions to your custom default_scopes. if neither of those solutions work for you, this might not be the right versioning gem for your use-case.

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