app/models/effective/trash.rb in effective_trash-0.2.6 vs app/models/effective/trash.rb in effective_trash-0.3.0

- old
+ new

@@ -1,11 +1,11 @@ module Effective class Trash < ActiveRecord::Base self.table_name = EffectiveTrash.trash_table_name.to_s belongs_to :trashed, polymorphic: true # The original item type and id. Note that this object will never exist as it's deleted. - belongs_to :user, optional: true # The user that destroyed the original resource + belongs_to :user # The user that destroyed the original resource # Attributes # trashed_type :string # trashed_id :integer # trashed_to_s :string @@ -14,11 +14,12 @@ # details :text # timestamps serialize :details, Hash - default_scope -> { order(updated_at: :desc) } + scope :deep, -> { includes(:user, :trashed) } + scope :sorted, -> { order(:id) } def to_s trashed_to_s.presence || [trashed_type, trashed_id].join(' ').presence || 'New Trash item' end @@ -47,9 +48,10 @@ # So this is a Trash item # When we delete ourselves, we restore this trash item first def restore! to_object.save!(validate: false) + destroy! end end end