Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add relation.reload to force reloading the records

  • Loading branch information...
commit 9a9f97af2815469e6f28dee9b88577251ef1b832 1 parent 3c5a7dc
Pratik lifo authored
8 activerecord/CHANGELOG
View
@@ -1,5 +1,13 @@
*Edge*
+* Add relation.reload to force reloading the records. [Pratik Naik]
+
+ topics = Topic.scoped
+ topics.to_a # force load
+ topics.first # returns a cached record
+ topics.reload
+ topics.first # Fetches a new record from the database
+
* Rename Model.conditions and relation.conditions to .where. [Pratik Naik]
Before :
6 activerecord/lib/active_record/relation.rb
View
@@ -120,6 +120,12 @@ def loaded?
@loaded
end
+ def reload
+ @loaded = false
+ @records = @first = nil
+ self
+ end
+
private
def method_missing(method, *args, &block)
15 activerecord/test/cases/relations_test.rb
View
@@ -55,6 +55,21 @@ def test_loaded_first
assert topics.loaded?
end
+ def test_reload
+ topics = Topic.scoped
+
+ assert_queries(1) do
+ 2.times { topics.to_a }
+ end
+
+ assert topics.loaded?
+
+ topics.reload
+ assert ! topics.loaded?
+
+ assert_queries(1) { topics.to_a }
+ end
+
def test_finding_with_conditions
assert_equal ["David"], Author.where(:name => 'David').map(&:name)
assert_equal ['Mary'], Author.where(["name = ?", 'Mary']).map(&:name)
Please sign in to comment.
Something went wrong with that request. Please try again.