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

fix: support zeroValue tag on DeletedAt #6011

Merged
merged 4 commits into from
Feb 1, 2023

Conversation

qiankunli
Copy link
Contributor

@qiankunli qiankunli commented Jan 31, 2023

type Book struct {
	ID        uint
	Name      string
	Pages     uint
	DeletedAt gorm.DeletedAt `gorm:"zeroValue:'1970-01-01 00:00:01'"`
}

it may be necessary for us to set the type of delete_at datetime. and if delete_at is null, we can not add it into the composite index. so we can use 1970-01-01 00:00:01 (or other values you like)as zero value.

if we query books, gorm can generate the sql automatically

select * from books where delete_at = '1970-01-01 00:00:01'

if we delete books, gorm can generate the sql automatically

update books set  delete_at = 'xx' where delete_at = '1970-01-01 00:00:01'

Signed-off-by: qiankunli <qiankun.li@qq.com>
@jinzhu jinzhu merged commit cfbcedb into go-gorm:master Feb 1, 2023
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