Fix issue when creating root category for new user

sq
This commit is contained in:
qowevisa 2024-11-27 20:28:39 +02:00
parent d55ba5c3c7
commit fc2b066c12

View File

@ -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
}