diff --git a/src/marten/db/field/base.cr b/src/marten/db/field/base.cr index d4942ecf..20461ac6 100644 --- a/src/marten/db/field/base.cr +++ b/src/marten/db/field/base.cr @@ -86,8 +86,7 @@ module Marten def perform_validation(record : Model) value = record.get_field_value(id) - validate_null(record, value) - validate_blank(record, value) + validate_presence(record, value) validate(record, value) end @@ -144,14 +143,10 @@ module Marten def validate(record, value) end - protected def validate_null(record : Model, value) + protected def validate_presence(record : Model, value) if value.nil? && !@null record.errors.add(id, null_error_message(record), type: :null) - end - end - - protected def validate_blank(record : Model, value) - if empty_value?(value) && !@blank + elsif empty_value?(value) && !@blank record.errors.add(id, blank_error_message(record), type: :blank) end end diff --git a/src/marten/db/field/slug.cr b/src/marten/db/field/slug.cr index 915436ef..a1f84f6c 100644 --- a/src/marten/db/field/slug.cr +++ b/src/marten/db/field/slug.cr @@ -41,11 +41,7 @@ module Marten end end - protected def validate_null(record : Model, value) - super if slugify.nil? - end - - protected def validate_blank(record : Model, value) + protected def validate_presence(record : Model, value) super if slugify.nil? end