aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrevor Turk <trevorturk@gmail.com>2010-08-19 14:49:10 -0500
committerTrevor Turk <trevorturk@gmail.com>2010-08-19 14:49:10 -0500
commit99c092d4e875856502946c29a1ae484eab3befb8 (patch)
tree0e336e14547155bc49775063e59fe1993cbaede6
parente6b6d3adaddae971a1ba5a1a6bfef942f4254028 (diff)
downloadrails-99c092d4e875856502946c29a1ae484eab3befb8.tar.gz
rails-99c092d4e875856502946c29a1ae484eab3befb8.tar.bz2
rails-99c092d4e875856502946c29a1ae484eab3befb8.zip
Note about validates_presence_of and nested attributes
-rw-r--r--activerecord/lib/active_record/nested_attributes.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/nested_attributes.rb b/activerecord/lib/active_record/nested_attributes.rb
index e09440d770..33611b410c 100644
--- a/activerecord/lib/active_record/nested_attributes.rb
+++ b/activerecord/lib/active_record/nested_attributes.rb
@@ -202,6 +202,22 @@ module ActiveRecord
# 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? } }