No commit activity in last 3 years
No release in over 3 years
Rails 3 assocation validation for id fields
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 3.0.0
 Project Readme

How to use

Validate that the id field is a saved record. It will ignore blank fields, so use presence if you need it.

validates :from_age_record_id, :presence => true, :association => {:class_name => 'AgeRecord'}
validates :user_id, :presence => true, :association => true

You can also set the message using the :message option:

validates :user_id, :association => {:message => 'was unretrievable'}

For polymorphic classes, pass your class_name option as a proc or use the new polymorphic_class option

class Item < ActiveRecord::Base
  # The new way to do polymorphic resource validation
  validates :owner_id, :presence => true, :association => {:polymorphic_class => 'owner_type'}
  # it calls record.send(:polymorphic_class)

  # If for some odd reasson you need to use a proc:
  validates :user_id, :presence => true, :association => {:class_name => Proc.new {|r| r.user_type || "User" }}
end

How to install

Add the following line to your bundle and install.

gem 'association_validator'

Todo

  • Tests