2017-10-11 15:20:56 +00:00
|
|
|
package models
|
|
|
|
|
2017-11-08 09:55:17 +00:00
|
|
|
// DeleteAuthorByID deletes an author by its ID
|
2017-11-07 15:35:10 +00:00
|
|
|
func DeleteAuthorByID(id int64) error {
|
2017-11-24 15:27:35 +00:00
|
|
|
// Check if the id is 0
|
|
|
|
if id == 0 {
|
2018-01-24 11:58:00 +00:00
|
|
|
return ErrIDCannotBeZero{}
|
2017-11-24 15:27:35 +00:00
|
|
|
}
|
|
|
|
|
2017-10-11 15:20:56 +00:00
|
|
|
// Delete the author
|
|
|
|
_, err := x.Id(id).Delete(&Author{})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete all book relations associated with that author
|
2017-11-07 15:35:10 +00:00
|
|
|
_, err = x.Delete(&AuthorBook{AuthorID: id})
|
2017-10-11 15:20:56 +00:00
|
|
|
|
|
|
|
return err
|
2017-11-07 15:35:10 +00:00
|
|
|
}
|