Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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'

@qiankunli qiankunli force-pushed the feat/support_zeroValue_tag branch from 51e5e3b to 80e7785 Compare February 1, 2023 03:57
@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.

2 participants