From fc2b066c12a7fd39467471136b386d9dfc1576f4 Mon Sep 17 00:00:00 2001 From: qowevisa Date: Wed, 27 Nov 2024 20:28:39 +0200 Subject: [PATCH] Fix issue when creating root category for new user sq --- db/category.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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 +}