go-gorm / gorm

The fantastic ORM library for Golang, aims to be developer friendly
https://gorm.io
MIT License
36.92k stars 3.93k forks source link

Gorm returning deleted values for no reason #3723

Closed Ometecuthli closed 4 years ago

Ometecuthli commented 4 years ago

I am using Gorm (Golang) and for some reason without making changes to my code, it starts returning deleted rows along the not-deleted rows. I have searched on the internet for hours but I am unable to find a reason.

err := db.Find(&subscribers).Error
if err != nil {
    writer.WriteHeader(http.StatusBadRequest)
    return
}

The above code will return deleted plus not-deleted users back. In the past, it would only return not-deleted users.

Can anyone explain to me what might be wrong or where to look?

I dont want to explicitly add .Where("deleted_at is null") to every query.

If I run my other projects, then this does NOT happen which is kinda strange right?

When I log my query it just says "SELECT * FROM "newsletter_subscribers"" without the "deleted_at" part.

github-actions[bot] commented 4 years ago

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 2 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.ioSearch Before Asking

gostega commented 8 months ago

Also having this issue, very frustrating. Adding .Where("deleted_at is null") seems to have no effect.