This repository has been archived on 2025-05-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
shop/app/models/Category.go

30 lines
704 B
Go

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
}