Cache columns for has_and_belongs_to_many associations

This avoids repeatedly calling SHOW COLUMNS when the association is queried
[#1738 state:committed]
This commit is contained in:
lukeludwig
2009-01-16 13:04:19 -06:00
committed by Michael Koziarski
parent fe013ce934
commit 3ee4e00918
3 changed files with 28 additions and 3 deletions

View File

@@ -775,4 +775,15 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase
end
end
end
def test_caching_of_columns
david = Developer.find(1)
# clear cache possibly created by other tests
david.projects.reset_column_information
assert_queries(1) { david.projects.columns; david.projects.columns }
# and again to verify that reset_column_information clears the cache correctly
david.projects.reset_column_information
assert_queries(1) { david.projects.columns; david.projects.columns }
end
end