aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorPascal Ehlert <pascal.ehlert@odadata.eu>2009-02-04 09:24:02 +0100
committerMichael Koziarski <michael@koziarski.com>2009-02-06 13:36:59 +1300
commit455a7633dbdb295de828eb2657433d47d85eb0bc (patch)
tree27db0f1c1b1fe997e0290a35f83a7fcc92da2b14 /activerecord/lib/active_record
parent4e4f961c112f1ffac73a1397d94dfbb4a10effae (diff)
downloadrails-455a7633dbdb295de828eb2657433d47d85eb0bc.tar.gz
rails-455a7633dbdb295de828eb2657433d47d85eb0bc.tar.bz2
rails-455a7633dbdb295de828eb2657433d47d85eb0bc.zip
Nested attribute accessors should ignore new records with truthy _delete key.
Signed-off-by: Michael Koziarski <michael@koziarski.com> [#1861 state:committed]
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/nested_attributes.rb8
1 files changed, 6 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/nested_attributes.rb b/activerecord/lib/active_record/nested_attributes.rb
index 8bfdadd0e3..5778223c74 100644
--- a/activerecord/lib/active_record/nested_attributes.rb
+++ b/activerecord/lib/active_record/nested_attributes.rb
@@ -86,7 +86,8 @@ module ActiveRecord
# For each key in the hash that starts with the string 'new' a new model
# will be instantiated. When the proc given with the <tt>:reject_if</tt>
# option evaluates to +false+ for a certain attribute hash no record will
- # be built for that hash.
+ # be built for that hash. (Rejecting new records can alternatively be done
+ # by utilizing the <tt>'_delete'</tt> key. Scroll down for more info.)
#
# params = { 'member' => {
# 'name' => 'joe', 'posts_attributes' => {
@@ -258,11 +259,14 @@ module ActiveRecord
# If a <tt>:reject_if</tt> proc exists for this association, it will be
# called with the attributes as its argument. If the proc returns a truthy
# value, the record is _not_ build.
+ #
+ # Alternatively, you can specify the <tt>'_delete'</tt> key to _not_ build
+ # a record. See should_destroy_nested_attributes_record? for more info.
def build_new_nested_attributes_record(association_name, attributes)
if reject_proc = self.class.reject_new_nested_attributes_procs[association_name]
return if reject_proc.call(attributes)
end
- send(association_name).build(attributes)
+ send(association_name).build(attributes) unless should_destroy_nested_attributes_record?(true, attributes)
end
# Assigns the attributes to the record specified by +id+. Or marks it for