aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2010-01-17 04:25:59 +0530
committerPratik Naik <pratiknaik@gmail.com>2010-01-17 04:25:59 +0530
commit8d87c80c19b7f0c0966fcfd52e7a6ed99d347a36 (patch)
tree230fc9030136c464c493ad8525ee47c81b03f249 /activerecord
parent7921a73acda62c3208b173858a40221cb33f9ff8 (diff)
downloadrails-8d87c80c19b7f0c0966fcfd52e7a6ed99d347a36.tar.gz
rails-8d87c80c19b7f0c0966fcfd52e7a6ed99d347a36.tar.bz2
rails-8d87c80c19b7f0c0966fcfd52e7a6ed99d347a36.zip
Make Relation#reload force load the records immediately
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/relation.rb5
-rw-r--r--activerecord/test/cases/relations_test.rb8
2 files changed, 8 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb
index 85bf878416..7c2a080ead 100644
--- a/activerecord/lib/active_record/relation.rb
+++ b/activerecord/lib/active_record/relation.rb
@@ -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
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index 195889f1df..acf247d27b 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -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