Skip to content

Commit

Permalink
Merge pull request #30791 from felipecvo/nested-attributes-doc
Browse files Browse the repository at this point in the history
Add update_only example to AR nested attributes doc [ci_skip]
  • Loading branch information
eileencodes committed Nov 13, 2017
2 parents 5744d00 + 71b1560 commit d2a04cc
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions activerecord/lib/active_record/nested_attributes.rb
Expand Up @@ -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
Expand Down

0 comments on commit d2a04cc

Please sign in to comment.