Skip to content
Snippets Groups Projects
Commit 25eb870f authored by Marcela Ribeiro de Oliveira's avatar Marcela Ribeiro de Oliveira
Browse files

update default attachment when delete attachment

parent a0b975a2
No related branches found
No related tags found
No related merge requests found
......@@ -36,7 +36,15 @@ class V1::LearningObjects::AttachmentController < ApplicationController
return render status: :not_found if @learning_object.nil? || @attachment.nil?
DeleteBitstreamWorker.perform_async(@attachment.id)
@attachment.destroy
if @learning_object.attachment == @attachment
@learning_object.attachment = nil
@learning_object.save
@attachment.destroy
@learning_object.reload
@learning_object.default_attachment
else
@attachment.destroy
end
render status: :ok
end
......
class UpdateLearningObjectAttachmentsForeignKey < ActiveRecord::Migration[5.0]
def change
remove_foreign_key :learning_object_attachments, :learning_object_attachments
add_foreign_key :learning_object_attachments, :learning_object_attachments, column: :attachment_id, on_delete: :cascade
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment