A fork of joshsusser/validates_existence with tests and logic to support newer versions of Rails
Switch branches/tags
Nothing to show
Pull request Compare This branch is 4 commits ahead of joshsusser:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
shoulda_macros
test
CHANGELOG
MIT-LICENSE
README.markdown
Rakefile
init.rb
validates_existence.gemspec

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.