diff --git a/app/controllers/v1/collections_controller.rb b/app/controllers/v1/collections_controller.rb index 21fc1f9cc49a57b0d82f7fd1e5387db4a8e07bc4..f98194f415a493d02a97252fbfae90702ca218c2 100644 --- a/app/controllers/v1/collections_controller.rb +++ b/app/controllers/v1/collections_controller.rb @@ -56,6 +56,10 @@ class V1::CollectionsController < ApplicationController # DELETE /v1/collections/1 # DELETE /v1/collections/1.json def destroy + items = @collection.collection_items.select(:id) + if !items.blank? + @collection.delete_items(items) + end @collection.destroy render status: :ok end diff --git a/app/models/collection.rb b/app/models/collection.rb index 632f2179105d5b251b5c79986c978475df9afd0c..cecb90f16d4d75fd3d81ab94a9ad6a647a919c06 100644 --- a/app/models/collection.rb +++ b/app/models/collection.rb @@ -36,6 +36,8 @@ class Collection < ApplicationRecord include Highlights include Complainable + acts_as_paranoid + has_many :collection_items, -> { order("position ASC") }, as: :collectionable, dependent: :destroy has_many :collections, through: :collection_items, source: :collectionable, source_type: 'Collection' has_many :learning_objects, through: :collection_items, source: :collectionable, source_type: 'LearningObject' @@ -50,7 +52,6 @@ class Collection < ApplicationRecord searchkick language: 'brazilian', match: :word_start, searchable: [:name, :description, :author], callbacks: :async - acts_as_paranoid has_paper_trail def search_data diff --git a/app/models/collection_item.rb b/app/models/collection_item.rb index 1a73aaed0001b832a727cc81d98110053ffd7b20..101e61d5b41f8ed4479647b771bfeccd66ac31aa 100644 --- a/app/models/collection_item.rb +++ b/app/models/collection_item.rb @@ -21,6 +21,8 @@ class CollectionItem < ApplicationRecord validates :collection, :collectionable, presence: true acts_as_list scope: :collection + acts_as_paranoid + def recipient collection end diff --git a/db/migrate/20170516111857_add_deleted_at_to_collection_items.rb b/db/migrate/20170516111857_add_deleted_at_to_collection_items.rb new file mode 100644 index 0000000000000000000000000000000000000000..abbe878fe27d87f74b19feeed88a854d25c1b020 --- /dev/null +++ b/db/migrate/20170516111857_add_deleted_at_to_collection_items.rb @@ -0,0 +1,6 @@ +class AddDeletedAtToCollectionItems < ActiveRecord::Migration[5.0] + def change + add_column :collection_items, :deleted_at, :datetime + add_index :collection_items, :deleted_at + end +end \ No newline at end of file