Skip to content
Snippets Groups Projects
Commit 736a9296 authored by Clarissa's avatar Clarissa
Browse files

#215: added deleted_at for collection_items; destroy all collection_items when...

#215: added deleted_at for collection_items; destroy all collection_items when collection is deleted
parent d6fb5ff5
No related branches found
No related tags found
No related merge requests found
......@@ -56,6 +56,11 @@ class V1::CollectionsController < ApplicationController
# DELETE /v1/collections/1
# DELETE /v1/collections/1.json
def destroy
items = @collection.collection_items.select(:id)
p items
if !items.blank?
@collection.delete_items(items)
end
@collection.destroy
render status: :ok
end
......
......@@ -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
......
......@@ -21,6 +21,8 @@ class CollectionItem < ApplicationRecord
validates :collection, :collectionable, presence: true
acts_as_list scope: :collection
acts_as_paranoid
def recipient
collection
end
......
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
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