package models import ( "gorm.io/gorm" "time" ) type Category struct { ID string `gorm:"size:36;not null;uniqueIndex;primary_key"` ParentID string `gorm:"size:36;"` Section Section SectionID string `gorm:"size:36;index"` Products []Product `gorm:"many2many:product_categories;"` Name string `gorm:"size:100;"` Image string CreatedAt time.Time UpdatedAt time.Time } func (p *Category) GetCategorie(db *gorm.DB, sectionID string) (*[]Category, error) { var categorie []Category err := db.Debug().Model(&Category{}).Order("created_at desc").Where("section_id = ?", sectionID).Find(&categorie).Error if err != nil { return nil, err } return &categorie, nil }