diff options
author | Felipe Oliveira <felipe.oliveira@youse.com.br> | 2017-10-03 08:41:12 -0300 |
---|---|---|
committer | Felipe Oliveira <felipe.oliveira@youse.com.br> | 2017-10-03 08:54:10 -0300 |
commit | 71b15603fddd85602813d1c96857e2674b6075d0 (patch) | |
tree | 1f21585076bd9333c6a9479b9f940e38a3de1066 /activerecord | |
parent | e0d2207ab321145c117c6d615ce209c6f873605d (diff) | |
download | rails-71b15603fddd85602813d1c96857e2674b6075d0.tar.gz rails-71b15603fddd85602813d1c96857e2674b6075d0.tar.bz2 rails-71b15603fddd85602813d1c96857e2674b6075d0.zip |
Add update_only example to AR nested attributes doc [ci_skip]
Diffstat (limited to 'activerecord')
-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 |