Module: CouchRest::Model::Validations::ClassMethods

Defined in:
lib/couchrest/model/validations.rb

Instance Method Summary collapse

Instance Method Details

#validates_casted_model(*args) ⇒ Object

Validates the associated casted model. This method should not be used within your code as it is automatically included when a CastedModel is used inside the model.



39
40
41
# File 'lib/couchrest/model/validations.rb', line 39

def validates_casted_model(*args)
  validates_with(CastedModelValidator, _merge_attributes(args))
end

#validates_uniqueness_of(*args) ⇒ Object

Validates if the field is unique for this type of document. Automatically creates a view if one does not already exist and performs a search for all matching documents.

Example:

class Person < CouchRest::Model::Base
  property :title, String

  validates_uniqueness_of :title
end

Asside from the standard options, you can specify the name of the view you’d like to use for the search inside the :view option. The following example would search for the code in side the all view, useful for when unique_id is used and you’d like to check before receiving a RestClient Conflict error:

validates_uniqueness_of :code, :view => 'all'

A :proxy parameter is also accepted if you would like to call a method on the document on which the view should be performed.

For Example:

# Same as not including proxy:
validates_uniqueness_of :title, :proxy => 'class'

# Person#company.people provides a proxy object for people
validates_uniqueness_of :title, :proxy => 'company.people'


73
74
75
# File 'lib/couchrest/model/validations.rb', line 73

def validates_uniqueness_of(*args)
  validates_with(UniquenessValidator, _merge_attributes(args))
end