2017-10-11 16:06:51 +00:00
|
|
|
package models
|
|
|
|
|
2017-11-08 09:55:17 +00:00
|
|
|
// DeletePublisherByID deletes a publisher by its ID
|
2017-11-07 15:35:10 +00:00
|
|
|
func DeletePublisherByID(id int64) error {
|
2017-10-11 16:06:51 +00:00
|
|
|
// Delete the publisher
|
|
|
|
_, err := x.Id(id).Delete(&Publisher{})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set all publisher to 0 on all book with this publisher
|
2017-11-07 15:35:10 +00:00
|
|
|
_, err = x.Table("books").Where("publisher = ?", id).Update(map[string]interface{}{"publisher": 0})
|
2017-10-11 16:06:51 +00:00
|
|
|
|
|
|
|
return err
|
2017-11-07 15:35:10 +00:00
|
|
|
}
|