fix: assciasions update

This commit is contained in:
2025-03-09 15:10:43 +07:00
parent df7c061d3a
commit 9e49d16a43
9 changed files with 36 additions and 16 deletions

View File

@@ -33,7 +33,12 @@ func (service *AuthorService) GetById(id uint) (*Author, error) {
return item, nil
}
func (service *AuthorService) Update(item Author) (Author, error) {
err := dal.Author.Preload(field.Associations).Save(&item)
var posts []*models.Post
for _, post := range item.Posts {
posts = append(posts, &post)
}
err := dal.Author.Posts.Model(&item).Replace(posts...)
_ = dal.Author.Save(&item)
return item, err
}
func (service *AuthorService) Delete(id uint) error {