aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-01-10 23:49:57 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-01-10 23:49:57 +0000
commit3ff5c5805fb490591b5839db8445869a48e93bcb (patch)
tree78e56b855f5e005cd897f5ea00f6c7f07a9a6e41 /activerecord/lib/active_record
parent59c2a4d51194058153b741b8682b1dd1b5e93939 (diff)
downloadrails-3ff5c5805fb490591b5839db8445869a48e93bcb.tar.gz
rails-3ff5c5805fb490591b5839db8445869a48e93bcb.tar.bz2
rails-3ff5c5805fb490591b5839db8445869a48e93bcb.zip
Added Base#reload that reloads the attributes of an object from the database #422 [Andreas Schwarz]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@376 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record')
-rwxr-xr-xactiverecord/lib/active_record/base.rb9
1 files changed, 8 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index bd7195a33b..8be5c7302a 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -874,6 +874,13 @@ module ActiveRecord #:nodoc:
toggle(attribute).update_attribute(attribute, self[attribute])
end
+ # Reloads the attributes of this object from the database.
+ def reload
+ clear_association_cache
+ @attributes.update(self.class.find(self.id).instance_variable_get('@attributes'))
+ return self
+ end
+
# Returns the value of attribute identified by <tt>attr_name</tt> after it has been type cast (for example,
# "2004-12-12" in a data column is cast to a date object, like Date.new(2004, 12, 12)).
# (Alias for the protected read_attribute method).
@@ -1211,4 +1218,4 @@ module ActiveRecord #:nodoc:
string[0..3] == "--- "
end
end
-end \ No newline at end of file
+end