Skip to content

Mongo:should check for createAt field is nil #3

@czyt

Description

@czyt

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions