Fix for category when searching parents when ParentID is zero

This commit is contained in:
qowevisa 2024-08-03 10:52:38 +03:00
parent 12fd07c0a3
commit 5ce7223b92

View File

@ -22,6 +22,7 @@ var (
)
func (c *Category) BeforeSave(tx *gorm.DB) error {
if c.ParentID != 0 {
var parent Category
if err := tx.Find(&parent, Category{ParentID: c.ParentID, UserID: c.UserID}).Error; err != nil {
return err
@ -29,6 +30,7 @@ func (c *Category) BeforeSave(tx *gorm.DB) error {
if parent.ID == 0 {
return ERROR_CATEGORY_PARENT_NOT_FOUND
}
}
var dup Category
if err := tx.Find(&dup, Category{Name: c.Name, UserID: c.UserID}).Error; err != nil {
return err