diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-04-26 09:22:43 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-04-26 09:22:43 -0700 |
commit | 8111facdb4d98ad9fce0892a68f790e32aa27002 (patch) | |
tree | e121260e9bae3563bacd8ba2e4110481e1755f8a /activerecord/lib | |
parent | 472f3fb61fd222742e60be6dbecc76b4b3839958 (diff) | |
parent | bb7024b6ecbc6f379275de3a7171bd0e84d39f29 (diff) | |
download | rails-8111facdb4d98ad9fce0892a68f790e32aa27002.tar.gz rails-8111facdb4d98ad9fce0892a68f790e32aa27002.tar.bz2 rails-8111facdb4d98ad9fce0892a68f790e32aa27002.zip |
Merged pull request #311 from joshk/assign_attributes.
AR update_attributes api is updated to reflect the addition of assign_att
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/persistence.rb | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb index a916c88348..998d237ada 100644 --- a/activerecord/lib/active_record/persistence.rb +++ b/activerecord/lib/active_record/persistence.rb @@ -136,22 +136,27 @@ module ActiveRecord # Updates the attributes of the model from the passed-in hash and saves the # record, all wrapped in a transaction. If the object is invalid, the saving # will fail and false will be returned. - def update_attributes(attributes) + # + # When updating model attributes, mass-assignment security protection is respected. + # If no +:as+ option is supplied then the :default scope will be used. + # If you want to bypass the protection given by +attr_protected+ and + # +attr_accessible+ then you can do so using the +:without_protection+ option. + def update_attributes(attributes, options = {}) # The following transaction covers any possible database side-effects of the # attributes assignment. For example, setting the IDs of a child collection. with_transaction_returning_status do - self.attributes = attributes + self.assign_attributes(attributes, options) save end end # Updates its receiver just like +update_attributes+ but calls <tt>save!</tt> instead # of +save+, so an exception is raised if the record is invalid. - def update_attributes!(attributes) + def update_attributes!(attributes, options = {}) # The following transaction covers any possible database side-effects of the # attributes assignment. For example, setting the IDs of a child collection. with_transaction_returning_status do - self.attributes = attributes + self.assign_attributes(attributes, options) save! end end |