diff --git a/db/category.go b/db/category.go index d29eac8..fe3a582 100644 --- a/db/category.go +++ b/db/category.go @@ -39,9 +39,6 @@ var ( ) func (c *Category) BeforeSave(tx *gorm.DB) error { - if c.ParentID == c.ID { - return ERROR_CATEGORY_SELF_REFERENCING - } if c.ParentID != 0 { var parent Category if err := tx.Find(&parent, c.ParentID).Error; err != nil { @@ -63,3 +60,10 @@ func (c *Category) BeforeSave(tx *gorm.DB) error { } return nil } + +func (c *Category) AfterCreate(tx *gorm.DB) error { + if c.ParentID == c.ID { + return ERROR_CATEGORY_SELF_REFERENCING + } + return nil +}