Library/models/authors_delete.go
konrad 3aabf3b086
All checks were successful
the build was successful
Added check if the ID is empty when deleting
2017-11-24 16:27:35 +01:00

24 lines
413 B
Go

package models
import "fmt"
// DeleteAuthorByID deletes an author by its ID
func DeleteAuthorByID(id int64) error {
// Check if the id is 0
if id == 0 {
return fmt.Errorf("ID cannot be 0")
}
// Delete the author
_, err := x.Id(id).Delete(&Author{})
if err != nil {
return err
}
// Delete all book relations associated with that author
_, err = x.Delete(&AuthorBook{AuthorID: id})
return err
}