diff options
author | Patrick J Cherry <patrick@bytemark.co.uk> | 2011-08-25 12:13:59 +0100 |
---|---|---|
committer | Patrick J Cherry <patrick@bytemark.co.uk> | 2011-08-25 12:13:59 +0100 |
commit | 36543941d784715e962599f7bf73f4680387e610 (patch) | |
tree | 893f9cd722b9ab3e123e81123805c2f91eb9d363 /lib/mauve/history.rb | |
parent | edfe588a9a39a761c7433f4d019201505081e289 (diff) |
Alert'destroy removes histories too,.
Diffstat (limited to 'lib/mauve/history.rb')
-rw-r--r-- | lib/mauve/history.rb | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/mauve/history.rb b/lib/mauve/history.rb index 74c5e3a..5a0caff 100644 --- a/lib/mauve/history.rb +++ b/lib/mauve/history.rb @@ -13,6 +13,8 @@ module Mauve belongs_to :alert belongs_to :history + after :destroy, :remove_unreferenced_histories + def self.migrate! # # This copies the alert IDs from the old History table to the new AlertHistories thing, but only if there are no AertHistories @@ -41,6 +43,12 @@ module Mauve end end + private + + def remove_unreferenced_histories + self.history.destroy unless self.history.alerts.count > 0 + end + end class History |