Module: Ohm::Model::Validations
- Includes:
- Ohm::Validations
- Included in:
- Defined in:
- lib/ohm.rb
Instance Method Summary (collapse)
-
- (Object) assert_unique(attrs)
Validates that the attribute or array of attributes are unique.
Methods included from Ohm::Validations
#assert, #assert_format, #assert_numeric, #assert_present, #errors, #valid?, #validate
Instance Method Details
- (Object) assert_unique(:name) - (Object) assert_unique([:street, :city])
Validates that the attribute or array of attributes are unique. For this, an index of the same kind must exist.
292 293 294 295 |
# File 'lib/ohm.rb', line 292 def assert_unique(attrs) result = db.sinter(*Array(attrs).map { |att| index_key_for(att, send(att)) }) assert result.empty? || !new? && result.include?(id.to_s), [attrs, :not_unique] end |