Make it so that when a user removes their own vote, the vote is soft deleted (the is_deleted flag is set) instead of hard deleted. Changes: * Add is_deleted flag to comment votes. * Relax uniqueness constraint so you can have multiple deleted votes on the same comment. You can still only have one active vote on the comment. * Add `soft_delete` method to Deletable concern.
20 lines
477 B
Ruby
20 lines
477 B
Ruby
module Deletable
|
|
extend ActiveSupport::Concern
|
|
|
|
class_methods do
|
|
def deletable
|
|
scope :active, -> { where(is_deleted: false) }
|
|
scope :deleted, -> { where(is_deleted: true) }
|
|
scope :undeleted, -> { where(is_deleted: false) }
|
|
|
|
define_method(:soft_delete) do |**options|
|
|
update(is_deleted: true, **options)
|
|
end
|
|
|
|
define_method(:soft_delete!) do |**options|
|
|
update!(is_deleted: true, **options)
|
|
end
|
|
end
|
|
end
|
|
end
|