aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorSebastian Martinez <sebastian@wyeworks.com>2011-03-27 18:52:21 -0300
committerSantiago Pastorino <santiago@wyeworks.com>2011-03-27 18:55:30 -0300
commit0e1fed537a7699a7ded02f77b71d222d7207c5ad (patch)
treea6d0acc8b1198593c3ca830755cbb643140de7d2 /activerecord/lib
parenteea6a65488e3f590d4d9cd922f54febb151799ad (diff)
downloadrails-0e1fed537a7699a7ded02f77b71d222d7207c5ad.tar.gz
rails-0e1fed537a7699a7ded02f77b71d222d7207c5ad.tar.bz2
rails-0e1fed537a7699a7ded02f77b71d222d7207c5ad.zip
Revert "Removed #update_attribute method. New #update_column method."
This reverts commit 45c233ef819dc7b67e259dd73f24721fec28b8c8. Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/associations/has_one_association.rb3
-rw-r--r--activerecord/lib/active_record/persistence.rb18
2 files changed, 11 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/associations/has_one_association.rb b/activerecord/lib/active_record/associations/has_one_association.rb
index dfcb116392..1d2e8667e4 100644
--- a/activerecord/lib/active_record/associations/has_one_association.rb
+++ b/activerecord/lib/active_record/associations/has_one_association.rb
@@ -34,8 +34,7 @@ module ActiveRecord
when :destroy
target.destroy
when :nullify
- target.send("#{reflection.foreign_key}=", nil)
- target.save(:validations => false)
+ target.update_attribute(reflection.foreign_key, nil)
end
end
end
diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb
index 3377a5934b..17a64b6e86 100644
--- a/activerecord/lib/active_record/persistence.rb
+++ b/activerecord/lib/active_record/persistence.rb
@@ -104,17 +104,19 @@ module ActiveRecord
became
end
- # Updates a single attribute of an object, without calling save.
+ # Updates a single attribute and saves the record.
+ # This is especially useful for boolean flags on existing records. Also note that
#
# * Validation is skipped.
- # * Callbacks are skipped.
- # * updated_at/updated_on column is not updated in any case.
+ # * Callbacks are invoked.
+ # * updated_at/updated_on column is updated if that column is available.
+ # * Updates all the attributes that are dirty in this object.
#
- def update_column(name, value)
+ def update_attribute(name, value)
name = name.to_s
raise ActiveRecordError, "#{name} is marked as readonly" if self.class.readonly_attributes.include?(name)
send("#{name}=", value)
- self.class.update_all({ name => value }, self.class.primary_key => id)
+ save(:validate => false)
end
# Updates the attributes of the model from the passed-in hash and saves the
@@ -154,7 +156,7 @@ module ActiveRecord
# Saving is not subjected to validation checks. Returns +true+ if the
# record could be saved.
def increment!(attribute, by = 1)
- increment(attribute, by).update_column(attribute, self[attribute])
+ increment(attribute, by).update_attribute(attribute, self[attribute])
end
# Initializes +attribute+ to zero if +nil+ and subtracts the value passed as +by+ (default is 1).
@@ -171,7 +173,7 @@ module ActiveRecord
# Saving is not subjected to validation checks. Returns +true+ if the
# record could be saved.
def decrement!(attribute, by = 1)
- decrement(attribute, by).update_column(attribute, self[attribute])
+ decrement(attribute, by).update_attribute(attribute, self[attribute])
end
# Assigns to +attribute+ the boolean opposite of <tt>attribute?</tt>. So
@@ -188,7 +190,7 @@ module ActiveRecord
# Saving is not subjected to validation checks. Returns +true+ if the
# record could be saved.
def toggle!(attribute)
- toggle(attribute).update_column(attribute, self[attribute])
+ toggle(attribute).update_attribute(attribute, self[attribute])
end
# Reloads the attributes of this object from the database.