fix: author fk

This commit is contained in:
2025-03-09 22:02:06 +07:00
parent baf4c67cfb
commit 447cc06876
2 changed files with 2 additions and 1 deletions

View File

@@ -32,6 +32,6 @@ type Comment struct {
Id uint `gorm:"primaryKey" ui:"hidden"`
Text string `ui:"label:Текст;"`
AuthorId uint `ui:"hidden"`
Author Author `ui:"label:Автор; field:Name;" gorm:"foreignKey:Id;references:AuthorId;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
Author Author `ui:"label:Автор; field:Name;" gorm:"foreignKey:AuthorId;references:Id;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
Posts []Post `ui:"label:Посты; field:Text;" gorm:"many2many:comments_post;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
}

View File

@@ -62,6 +62,7 @@ func (service *AuthorService) Delete(id uint) error {
_, err := dal.Author.Unscoped().Where(dal.Author.Id.Eq(id)).Delete()
return err
}
func (service *AuthorService) Count() (int64, error) {
amount, err := dal.Author.Count()
return amount, err