1
"""relationship_caching.py
3
Load a set of Person and Address objects, specifying that
4
related PostalCode, City, Country objects should be pulled from long
8
from environment import Session, root
9
from model import Person, Address, cache_address_bits
10
from sqlalchemy.orm import joinedload
13
for p in Session.query(Person).options(joinedload(Person.addresses), cache_address_bits):
17
print "\n\nIf this was the first run of relationship_caching.py, SQL was likely emitted to "\
18
"load postal codes, cities, countries.\n"\
19
"If run a second time, only a single SQL statement will run - all "\
20
"related data is pulled from cache.\n"\
21
"To clear the cache, delete the directory %r. \n"\
22
"This will cause a re-load of cities, postal codes and countries on "\
24
% os.path.join(root, 'container_file')