Module: BlindIndex::Mongoid::UniquenessValidator

Defined in:
lib/blind_index/mongoid.rb

Instance Method Summary collapse

Instance Method Details

#create_criteria(base, document, attribute, value) ⇒ Object

change attribute name here instead of validate_each for better error message



51
52
53
54
55
56
57
# File 'lib/blind_index/mongoid.rb', line 51

def create_criteria(base, document, attribute, value)
  klass = document.class
  if klass.respond_to?(:blind_indexes) && (bi = klass.blind_indexes[attribute])
    attribute = bi[:bidx_attribute]
  end
  super(base, document, attribute, value)
end

#validate_each(record, attribute, value) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/blind_index/mongoid.rb', line 42

def validate_each(record, attribute, value)
  klass = record.class
  if klass.respond_to?(:blind_indexes) && (bi = klass.blind_indexes[attribute])
    value = record.read_attribute_for_validation(bi[:bidx_attribute])
  end
  super(record, attribute, value)
end