Permalink
Browse files

Merge pull request #30791 from felipecvo/nested-attributes-doc

Add update_only example to AR nested attributes doc [ci_skip]
  • Loading branch information...
eileencodes committed Nov 13, 2017
2 parents 5744d00 + 71b1560 commit d2a04ccc40c456bc62de66f3f76a818874163245
Showing with 12 additions and 0 deletions.
  1. +12 −0 activerecord/lib/active_record/nested_attributes.rb
@@ -63,6 +63,18 @@ class TooManyRecords < ActiveRecordError
# member.update params[:member]
# member.avatar.icon # => 'sad'
#
# If you want to update the current avatar without providing the id, you must add <tt>:update_only</tt> option.
#
# class Member < ActiveRecord::Base
# has_one :avatar
# accepts_nested_attributes_for :avatar, update_only: true
# end
#
# params = { member: { avatar_attributes: { icon: 'sad' } } }
# member.update params[:member]
# member.avatar.id # => 2
# member.avatar.icon # => 'sad'
#
# By default you will only be able to set and update attributes on the
# associated model. If you want to destroy the associated model through the
# attributes hash, you have to enable it first using the

0 comments on commit d2a04cc

Please sign in to comment.