aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations/has_many_associations_test.rb
diff options
context:
space:
mode:
authorNeeraj Singh <neerajdotname@gmail.com>2010-11-14 21:54:24 -0500
committerAaron Patterson <aaron.patterson@gmail.com>2010-11-15 10:12:23 -0800
commit7c5c1a07c03ec03536636c26e09b80b29a59beed (patch)
tree002109e6cf69ff0e957a582a19944d015c2176fb /activerecord/test/cases/associations/has_many_associations_test.rb
parent022519a032c830afa1fa1b9d02a27acf5588476b (diff)
downloadrails-7c5c1a07c03ec03536636c26e09b80b29a59beed.tar.gz
rails-7c5c1a07c03ec03536636c26e09b80b29a59beed.tar.bz2
rails-7c5c1a07c03ec03536636c26e09b80b29a59beed.zip
if association is already loaded and if a find operation is performed on the already loaded association list with an empty hash then do not perform another sql
[#5972 state:resolved]
Diffstat (limited to 'activerecord/test/cases/associations/has_many_associations_test.rb')
-rw-r--r--activerecord/test/cases/associations/has_many_associations_test.rb11
1 files changed, 11 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb
index 1ddc627940..ecfc769f3a 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -66,6 +66,17 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
assert_equal 'exotic', bulb.name
end
+ def test_no_sql_should_be_fired_if_association_already_loaded
+ car = Car.create(:name => 'honda')
+ bulb = car.bulbs.create
+ bulbs = Car.first.bulbs
+ bulbs.inspect # to load all instances of bulbs
+ assert_no_queries do
+ bulbs.first()
+ bulbs.first({})
+ end
+ end
+
def test_create_resets_cached_counters
person = Person.create!(:first_name => 'tenderlove')
post = Post.first