luckyframework / luckyframework/avram
Models can be deleted directly... but they shouldn't be
Nobody has claimed this yet.
- Dominant language
- Crystal
- Stars
- 183
- Forks
- 67
- PR merge metrics
- No merged PRs in 30d
Description
Not sure why I never noticed this before, but we have this method:
https://github.com/luckyframework/avram/blob/80311556f0cc2b1186c88c97a74a6494ad87f48e/src/avram/primary_key_methods.cr#L75-L77
This means you can do this
```
user = UserQuery.find(1)
user.delete
SaveUser.update!(user)
```
The issue here is that this sort of breaks the repository pattern, and also circumvents the whole point of Delete operations. You can't run any other SQL directly against a model, so deleting a model directly should also be restricted.
I didn't look too far in to it, but it's possible this existed before we added DeleteOperations... In any case, we should deprecate the direct use of calling `model.delete`, then later remove it so you have to use a DeleteOperation instead (or bulk query).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with src/avram/primary_key_methods.cr at lines 75-77 and trace how model.delete relates to DeleteOperations and bulk queries. Determine the deprecation and eventual removal scope, then verify that deletion is restricted to the intended operation APIs without breaking existing behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- crystal
- Domain
- databases
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100