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

Mongo:should check for createAt field is nil #3

Open
czyt opened this issue Sep 20, 2022 · 0 comments
Open

Mongo:should check for createAt field is nil #3

czyt opened this issue Sep 20, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@czyt
Copy link
Collaborator

czyt commented Sep 20, 2022

add such check

if data.CreatedAt.IsZero() {
		data.CreatedAt = time.Now()
	}

or add hook in model

func (u *User) Creating() error {
	if u.CreatedAt.IsZero() {
		u.CreatedAt = time.Now()
	}
	return nil
}

func (u *User) Updating() error {
	if u.UpdatedAt.IsZero() {
		u.UpdatedAt = time.Now()
	}
	return nil
}
@czyt czyt changed the title should check for createAt field is nil Mongo:should check for createAt field is nil Sep 23, 2022
@czyt czyt added the bug Something isn't working label Sep 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant