Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Rails plugin that provides a validates_existence_of method for ActiveRecord models to check existence of records referenced by belongs_to associations..

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 MIT-LICENSE
Octocat-spinner-32 README.markdown
Octocat-spinner-32 Rakefile
Octocat-spinner-32 init.rb
README.markdown

ValidatesExistence

This plugin adds a new validates_existence_of method to ActiveRecord::Base.

The validates_existence_of validator checks that a foreign key in a belongs_to association points to an existing record. If :allow_nil => true, then the key itself may be nil. A non-nil key requires that the foreign object must exist. Works with polymorphic belongs_to.

The default error message is "does not exist".

Example

class Person < ActiveRecord::Base
  belongs_to :address
  validates_existence_of :address
end

Note that this validation performs a query to see if the record in question exists.

Copyright (c) 2007-2008 Josh Susser. Released under the MIT license.

Something went wrong with that request. Please try again.