对soft delete字段设置默认值后,新增数据在使用该默认值后,导致无法查询
DeletedTime soft_delete.DeletedAt
gorm:"default:2006-01-02 15:04:05;column:deleted_time;type:timestamp with time zone" json:"deleted_time"
期望结果: 对soft delete字段设置默认值后,SQL查询语句判断逻辑应该从 deleted_time=null 变更为 deleted_time='2006-01-02 15:04:05'
Comment From: github-actions[bot]
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 30 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.io ✨ Search Before Asking ✨
Comment From: li-jin-gou
https://gorm.cn/zh_CN/docs/delete.html#%E6%9F%A5%E6%89%BE%E8%A2%AB%E8%BD%AF%E5%88%A0%E9%99%A4%E7%9A%84%E8%AE%B0%E5%BD%95 @jessonzj
Comment From: jessonzj
这种需要修改之前代码的查询逻辑,同时后续开发维护不方便 @li-jin-gou 。是否可以在这一行把nil换成 default和nil https://github.com/go-gorm/gorm/blob/b13d1757fab7093d769afc02573ee3c359faeb26/soft_delete.go#L81
Comment From: li-jin-gou
2006-01-02 15:04:05; 不太建议这样做,通过时间来做软删的话一般都是使用删除数据的时间来填充的,这样既实现了软删,又可以确定数据的删除时间。 如果使用固定值作为软删标示的话可以参考 https://github.com/go-gorm/soft_delete#flag-mode
Comment From: jessonzj
我是遇到使用软删除字段与其他字段作为唯一索引时 如果软删除字段为null,唯一索引会失效,因此才给软删除加默认值
Comment From: jessonzj
而且如果用户对软删除字段设置了默认值,那么在业务上 对于他们来说这个默认值的记录应该是能正常查询的(而不是使用unscoped来查询),否则的话就不会用默认值了 而是用随机值或当前时间