Skip to content
This repository
Browse code

Make Relation#reload force load the records immediately

  • Loading branch information...
commit 8d87c80c19b7f0c0966fcfd52e7a6ed99d347a36 1 parent 7921a73
Pratik authored January 17, 2010
5  activerecord/lib/active_record/relation.rb
@@ -124,12 +124,13 @@ def loaded?
124 124
     end
125 125
 
126 126
     def reload
127  
-      @loaded = false
128 127
       reset
  128
+      to_a # force reload
  129
+      self
129 130
     end
130 131
 
131 132
     def reset
132  
-      @first = @last = @to_sql = @order_clause = @scope_for_create = @arel = nil
  133
+      @first = @last = @to_sql = @order_clause = @scope_for_create = @arel = @loaded = nil
133 134
       @records = []
134 135
       self
135 136
     end
8  activerecord/test/cases/relations_test.rb
@@ -68,10 +68,12 @@ def test_reload
68 68
 
69 69
     assert topics.loaded?
70 70
 
71  
-    topics.reload
72  
-    assert ! topics.loaded?
  71
+    original_size = topics.to_a.size
  72
+    Topic.create! :title => 'fake'
73 73
 
74  
-    assert_queries(1) { topics.to_a }
  74
+    assert_queries(1) { topics.reload }
  75
+    assert_equal original_size + 1, topics.size
  76
+    assert topics.loaded?
75 77
   end
76 78
 
77 79
   def test_finding_with_conditions

0 notes on commit 8d87c80

Please sign in to comment.
Something went wrong with that request. Please try again.