Fix Parent finding issue with BeforeSave hook and duplicate finding error for category
This commit is contained in:
parent
9b77237d50
commit
8a7d52efda
|
@ -40,7 +40,7 @@ var (
|
|||
func (c *Category) BeforeSave(tx *gorm.DB) error {
|
||||
if c.ParentID != 0 {
|
||||
var parent Category
|
||||
if err := tx.Find(&parent, c.ID).Error; err != nil {
|
||||
if err := tx.Find(&parent, c.ParentID).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if parent.ID == 0 {
|
||||
|
@ -54,7 +54,7 @@ func (c *Category) BeforeSave(tx *gorm.DB) error {
|
|||
if err := tx.Find(&dup, Category{Name: c.Name, UserID: c.UserID}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if dup.ID != 0 {
|
||||
if c.ID != dup.ID && dup.ID != 0 {
|
||||
return ERROR_CATEGORY_NAME_NOT_UNIQUE
|
||||
}
|
||||
return nil
|
||||
|
|
Loading…
Reference in New Issue
Block a user