From 1f3a1fedf951dbc4b72d178e2a649c4afd2f1566 Mon Sep 17 00:00:00 2001 From: Amparo Luna + Guillermo Iguaran Date: Wed, 2 Jan 2013 11:46:58 -0500 Subject: Rename update_attributes method to update, keep update_attributes as an alias --- activerecord/lib/active_record/persistence.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'activerecord/lib/active_record/persistence.rb') diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb index 4d1a9c94b7..287c42a481 100644 --- a/activerecord/lib/active_record/persistence.rb +++ b/activerecord/lib/active_record/persistence.rb @@ -212,7 +212,7 @@ 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) + def update(attributes) # 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 @@ -220,10 +220,12 @@ module ActiveRecord save end end + + alias update_attributes update # Updates its receiver just like +update_attributes+ but calls save! instead # of +save+, so an exception is raised if the record is invalid. - def update_attributes!(attributes) + def update!(attributes) # 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 @@ -231,6 +233,8 @@ module ActiveRecord save! end end + + alias update_attributes! update! # Updates a single attribute of an object, without having to explicitly call save on that object. # @@ -406,13 +410,13 @@ module ActiveRecord def create_or_update raise ReadOnlyRecord if readonly? - result = new_record? ? create : update + result = new_record? ? create_record : update_record result != false end # Updates the associated record with values matching those of the instance attributes. # Returns the number of affected rows. - def update(attribute_names = @attributes.keys) + def update_record(attribute_names = @attributes.keys) attributes_with_values = arel_attributes_with_values_for_update(attribute_names) if attributes_with_values.empty? @@ -426,7 +430,7 @@ module ActiveRecord # Creates a record with values matching those of the instance attributes # and returns its id. - def create(attribute_names = @attributes.keys) + def create_record(attribute_names = @attributes.keys) attributes_values = arel_attributes_with_values_for_create(attribute_names) new_id = self.class.unscoped.insert attributes_values -- cgit v1.2.3