diff options
author | Eileen M. Uchitelle <eileencodes@users.noreply.github.com> | 2017-11-12 19:17:15 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-12 19:17:15 -0500 |
commit | d2a04ccc40c456bc62de66f3f76a818874163245 (patch) | |
tree | ec1c0f9e962a1028c6d1c4df94928432c2dbcdf3 /activerecord/lib/active_record | |
parent | 5744d00f5d22bbf1efde180431eb3daac76007e8 (diff) | |
parent | 71b15603fddd85602813d1c96857e2674b6075d0 (diff) | |
download | rails-d2a04ccc40c456bc62de66f3f76a818874163245.tar.gz rails-d2a04ccc40c456bc62de66f3f76a818874163245.tar.bz2 rails-d2a04ccc40c456bc62de66f3f76a818874163245.zip |
Merge pull request #30791 from felipecvo/nested-attributes-doc
Add update_only example to AR nested attributes doc [ci_skip]
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/nested_attributes.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/nested_attributes.rb b/activerecord/lib/active_record/nested_attributes.rb index 435c81c153..fa20bce3a9 100644 --- a/activerecord/lib/active_record/nested_attributes.rb +++ b/activerecord/lib/active_record/nested_attributes.rb @@ -63,6 +63,18 @@ module ActiveRecord # 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 |