From 93a05576b8a92790f09e6f41890a66abb91fdeed Mon Sep 17 00:00:00 2001 From: Aaron Lindsay Date: Mon, 17 Jul 2017 20:24:47 -0400 Subject: [PATCH] Delete prices when deleting security --- securities.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/securities.go b/securities.go index 006b2cb..bb65461 100644 --- a/securities.go +++ b/securities.go @@ -199,6 +199,14 @@ func DeleteSecurity(s *Security) error { return errors.New("Cannot delete security which is user's default currency") } + // Remove all prices involving this security (either of this security, or + // using it as a currency) + _, err = transaction.Exec("DELETE * FROM prices WHERE SecurityId=? OR CurrencyId=?", s.SecurityId, s.SecurityId) + if err != nil { + transaction.Rollback() + return err + } + count, err := transaction.Delete(s) if err != nil { transaction.Rollback()