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

Merge branch 'bugs' into 'master'

#215: added deleted_at for collection_items; destroy all collection_items when collection is deleted

See merge request !423
parents bdff910e 1d2c450c
No related branches found
No related tags found
No related merge requests found
...@@ -56,6 +56,10 @@ class V1::CollectionsController < ApplicationController ...@@ -56,6 +56,10 @@ class V1::CollectionsController < ApplicationController
# DELETE /v1/collections/1 # DELETE /v1/collections/1
# DELETE /v1/collections/1.json # DELETE /v1/collections/1.json
def destroy def destroy
items = @collection.collection_items.select(:id)
if !items.blank?
@collection.delete_items(items)
end
@collection.destroy @collection.destroy
render status: :ok render status: :ok
end end
......
...@@ -36,6 +36,8 @@ class Collection < ApplicationRecord ...@@ -36,6 +36,8 @@ class Collection < ApplicationRecord
include Highlights include Highlights
include Complainable include Complainable
acts_as_paranoid
has_many :collection_items, -> { order("position ASC") }, as: :collectionable, dependent: :destroy has_many :collection_items, -> { order("position ASC") }, as: :collectionable, dependent: :destroy
has_many :collections, through: :collection_items, source: :collectionable, source_type: 'Collection' has_many :collections, through: :collection_items, source: :collectionable, source_type: 'Collection'
has_many :learning_objects, through: :collection_items, source: :collectionable, source_type: 'LearningObject' has_many :learning_objects, through: :collection_items, source: :collectionable, source_type: 'LearningObject'
...@@ -50,7 +52,6 @@ class Collection < ApplicationRecord ...@@ -50,7 +52,6 @@ class Collection < ApplicationRecord
searchkick language: 'brazilian', match: :word_start, searchable: [:name, :description, :author], callbacks: :async searchkick language: 'brazilian', match: :word_start, searchable: [:name, :description, :author], callbacks: :async
acts_as_paranoid
has_paper_trail has_paper_trail
def search_data def search_data
......
...@@ -21,6 +21,8 @@ class CollectionItem < ApplicationRecord ...@@ -21,6 +21,8 @@ class CollectionItem < ApplicationRecord
validates :collection, :collectionable, presence: true validates :collection, :collectionable, presence: true
acts_as_list scope: :collection acts_as_list scope: :collection
acts_as_paranoid
def recipient def recipient
collection collection
end 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