Library/models/publishers_delete.go

26 lines
495 B
Go
Raw Normal View History

package models
import "fmt"
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 {
// Check if the id is 0
if id == 0 {
return fmt.Errorf("ID cannot be 0")
}
// 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-29 15:23:19 +00:00
_, err = x.Table("books").
2017-11-30 14:48:03 +00:00
Where("publisher_id = ?", id).
Update(map[string]interface{}{"publisher_id": 0})
return err
2017-11-07 15:35:10 +00:00
}