Sha256: 1ffddf9437d7e8b63df09d250163fcf6e197a85e6252a3f3ba7e415a7e05a6ae
Contents?: true
Size: 808 Bytes
Versions: 2
Compression:
Stored size: 808 Bytes
Contents
module Volt class UniqueValidator def self.validate(model, field_name, args) if RUBY_PLATFORM != 'opal' if args value = model.get(field_name) query = {} # Check to see if any other documents have this value. query[field_name.to_s] = value query['_id'] = { '$ne' => model._id } # Check if the value is taken # TODO: need a way to handle scope for unique return $page.store.get(model.path[-2]).where(query).fetch_first do |item| if item message = (args.is_a?(Hash) && args[:message]) || 'is already taken' # return the error next {field_name: [message]} end end end end # no errors {} end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
volt-0.9.1.pre3 | lib/volt/models/validators/unique_validator.rb |
volt-0.9.1.pre2 | lib/volt/models/validators/unique_validator.rb |