Commit 8be4fcb7 by Edward Poot Committed by GitHub

Add AssociationNotSoftDestroyedValidator

parent b63f446d
......@@ -299,5 +299,14 @@ module ActiveRecord
class UniquenessValidator < ActiveModel::EachValidator
prepend UniquenessParanoiaValidator
end
class AssociationNotSoftDestroyedValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
# if association is soft destroyed, add an error
if value.present? && value.deleted?
record.errors[attribute] << 'has been soft-deleted'
end
end
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment