Permalink
Browse files

Note about validates_presence_of and nested attributes

  • Loading branch information...
1 parent e6b6d3a commit 99c092d4e875856502946c29a1ae484eab3befb8 @trevorturk trevorturk committed Aug 19, 2010
Showing with 16 additions and 0 deletions.
  1. +16 −0 activerecord/lib/active_record/nested_attributes.rb
@@ -202,6 +202,22 @@ class TooManyRecords < ActiveRecordError
# You would need to modify it to look like this:
#
# attr_accessible :name, :posts_attributes
+ #
+ # === Validating the presence of a parent model
+ #
+ # If you want to validate that a child record is associated with a parent
+ # record, you can use <tt>validates_presence_of</tt> and
+ # <tt>inverse_of</tt> as this example illustrates:
+ #
+ # class Member < ActiveRecord::Base
+ # has_many :posts, :inverse_of => :member
+ # accepts_nested_attributes_for :posts
+ # end
+ #
+ # class Post < ActiveRecord::Base
+ # belongs_to :member, :inverse_of => :posts
+ # validates_presence_of :member
+ # end
module ClassMethods
REJECT_ALL_BLANK_PROC = proc { |attributes| attributes.all? { |_, value| value.blank? } }

0 comments on commit 99c092d

Please sign in to comment.