1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Make Relation#reload force load the records immediately

This commit is contained in:
Pratik Naik 2010-01-17 04:25:59 +05:30
parent 7921a73acd
commit 8d87c80c19
2 changed files with 8 additions and 5 deletions

View file

@ -124,12 +124,13 @@ module ActiveRecord
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 file

@ -68,10 +68,12 @@ class RelationTest < ActiveRecord::TestCase
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