remove redundancy in models BeforeInsert hook

This commit is contained in:
dhax 2017-10-13 01:01:31 +02:00
parent c3271d7dcf
commit 2dc0f02d1c
2 changed files with 2 additions and 8 deletions

View file

@ -33,10 +33,7 @@ func (a *Account) BeforeInsert(db orm.DB) error {
a.CreatedAt = now a.CreatedAt = now
a.UpdatedAt = now a.UpdatedAt = now
} }
if err := a.Validate(); err != nil { return a.Validate()
return err
}
return nil
} }
// BeforeUpdate hook executed before database update operation. // BeforeUpdate hook executed before database update operation.

View file

@ -25,11 +25,8 @@ func (p *Profile) BeforeInsert(db orm.DB) error {
// BeforeUpdate hook executed before database update operation. // BeforeUpdate hook executed before database update operation.
func (p *Profile) BeforeUpdate(db orm.DB) error { func (p *Profile) BeforeUpdate(db orm.DB) error {
if err := p.Validate(); err != nil {
return err
}
p.UpdatedAt = time.Now() p.UpdatedAt = time.Now()
return nil return p.Validate()
} }
// Validate validates Profile struct and returns validation errors. // Validate validates Profile struct and returns validation errors.