FIX: leaving around useless drafts after posting

This commit is contained in:
Sam Saffron
2015-06-02 13:45:47 +10:00
parent d459cb95dc
commit 0fd1974838
3 changed files with 28 additions and 0 deletions

View File

@@ -34,6 +34,15 @@ class Draft < ActiveRecord::Base
find_by(user_id: user, draft_key: key)
end
end
def self.cleanup!
exec_sql("DELETE FROM drafts where sequence < (
SELECT max(s.sequence) from draft_sequences s
WHERE s.draft_key = drafts.draft_key AND
s.user_id = drafts.user_id
)")
end
end
# == Schema Information