diff --git a/lib/goo/validators/implementations/unique.rb b/lib/goo/validators/implementations/unique.rb new file mode 100644 index 00000000..feb13a4b --- /dev/null +++ b/lib/goo/validators/implementations/unique.rb @@ -0,0 +1,20 @@ +module Goo + module Validators + class Unique < ValidatorBase + include Validator + + key :unique + + error_message ->(obj) { "`#{@attr}` must be unique. " + + "There are other model instances with the same attribute value `#{@value}`."} + + validity_check -> (obj) do + return true if @value.nil? + + !Goo::SPARQL::Queries.duplicate_attribute_value?(@inst,@attr) + end + + + end + end +end \ No newline at end of file