Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Make Relation#reload force load the records immediately

  • Loading branch information...
commit 8d87c80c19b7f0c0966fcfd52e7a6ed99d347a36 1 parent 7921a73
@lifo lifo authored
View
5 activerecord/lib/active_record/relation.rb
@@ -124,12 +124,13 @@ def loaded?
end
def reload
- @loaded = false
reset
+ to_a # force reload
+ self
end
def reset
- @first = @last = @to_sql = @order_clause = @scope_for_create = @arel = nil
+ @first = @last = @to_sql = @order_clause = @scope_for_create = @arel = @loaded = nil
@records = []
self
end
View
8 activerecord/test/cases/relations_test.rb
@@ -68,10 +68,12 @@ def test_reload
assert topics.loaded?
- topics.reload
- assert ! topics.loaded?
+ original_size = topics.to_a.size
+ Topic.create! :title => 'fake'
- assert_queries(1) { topics.to_a }
+ assert_queries(1) { topics.reload }
+ assert_equal original_size + 1, topics.size
+ assert topics.loaded?
end
def test_finding_with_conditions

0 comments on commit 8d87c80

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