diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index b0c83e869..caf0b4bda 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -521,10 +521,10 @@ class IssuesController < ApplicationController def delete_journal @issue = Issue.find(params[:id]) begin - forge_acts = ForgeMessage.where(:forge_message_type => "Journal", :forge_message_id => params[:journal_id]).first - forge_acts.destroy unless forge_acts.nil? - at_message = AtMessage.where(:at_message_type => "Journal", :at_message_id => params[:journal_id]).first - at_message.destroy unless at_message.nil? + forge_acts = ForgeMessage.where(:forge_message_type => "Journal", :forge_message_id => params[:journal_id]) + forge_acts.destroy_all unless forge_acts.empty? + at_message = AtMessage.where(:at_message_type => "Journal", :at_message_id => params[:journal_id]) + at_message.destroy_all unless at_message.empty? Journal.delete(params[:journal_id]) rescue Exception => e puts e diff --git a/db/migrate/20160830090214_delete_null_at_messages.rb b/db/migrate/20160830090214_delete_null_at_messages.rb new file mode 100644 index 000000000..304a6bc4e --- /dev/null +++ b/db/migrate/20160830090214_delete_null_at_messages.rb @@ -0,0 +1,17 @@ +class DeleteNullAtMessages < ActiveRecord::Migration + def up + count = AtMessage.all.count / 30 + 2 + transaction do + for i in 1 ... count do i + AtMessage.page(i).per(30).each do |am| + if am.at_message.nil? + am.destroy + end + end + end + end + end + + def down + end +end diff --git a/db/schema.rb b/db/schema.rb index 414f2d2be..b5bd5f778 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20160824073554) do +ActiveRecord::Schema.define(:version => 20160830090214) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false