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

Stop using gorm.Model to disable gorm side effects #155

Merged
merged 1 commit into from
Mar 19, 2023
Merged

Conversation

ghost
Copy link

@ghost ghost commented Mar 17, 2023

Description

By default gorm.Model includes a number of fields extra fields CreatedAt/UpdatedAt and DeletedAt. Because DeletedAt is present gorm automatically enables soft-delete, which results in gorm not remove the records from the DB upon delete instead it just sets DeletedAt, and then hides them from further queries.

As we are using db.Raw gorm doesn't hide these records and will show deleted records and not deleted records togther. For this reason this commit drops the gorm.Model and replaces it simply with the ID primary key that is a requirement.

Note(sambetts): If we want to add CreatedAt/UpdatedAt fields in the future we should add them to the API model and manage them in the gorm driver, so that they are available to query through odata.

Type of Change

[X] Bug Fix
[ ] New Feature
[ ] Breaking Change
[ ] Refactor
[ ] Documentation
[ ] Other (please describe)

Checklist

  • I have read the contributing guidelines
  • Existing issues have been referenced (where applicable)
  • I have verified this change is not present in other open pull requests
  • Functionality is documented
  • All code style checks pass
  • New code contribution is covered by automated tests
  • All new and existing tests pass

@ghost ghost self-requested a review as a code owner March 17, 2023 16:49
By default gorm.Model includes a number of fields extra fields
CreatedAt/UpdatedAt and DeletedAt. Because DeletedAt is present gorm
automatically enables soft-delete, which results in gorm not remove the
records from the DB upon delete instead it just sets DeletedAt, and then
hides them from further queries.

As we are using db.Raw gorm doesn't hide these records and will show
deleted records and not deleted records togther. For this reason this
commit drops the gorm.Model and replaces it simply with the ID primary
key that is a requirement.

Note(sambetts): If we want to add CreatedAt/UpdatedAt fields in the
future we should add them to the API model and manage them in the gorm
driver, so that they are available to query through odata.
@FrimIdan FrimIdan merged commit 49a3635 into main Mar 19, 2023
@FrimIdan FrimIdan deleted the fix_delete branch March 19, 2023 08:00
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

Successfully merging this pull request may close these issues.

None yet

2 participants