couchrest-uniqueness-validation

Validates that the specified attribute is unique across documents with the same couchrest-type using a view.

@note

You have to define a design doc view.

@see rdoc.info/rdoc/couchrest/couchrest/blob/1b34fe4b60694683e98866a51c2109c1885f7e42/CouchRest/Mixins/Views/ClassMethods.html#view_by-instance_method for more details about views.

@example [Usage]

class User

  property :nickname
  property :login

  view_by :nickname

  # assumes that a view :by_nickname is present
  validates_uniqueness_of :nickname

  # uses a different from default view 
  validates_uniqueness_of :login, :view => 'my_custom_view'

  # a call to valid? will return false unless no other document exists with
  # the same couchrest-type, nickname and login
end

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright © 2010 [email protected]. See LICENSE for details.