step in case the given property references a non-compiled mapper
(as it did in the case of the tutorial !)
- [ticket:277] check for pg sequence already existing before create
+- if a contextual session is established via MapperExtension.get_session
+(as it is using the sessioncontext plugin, etc), a lazy load operation
+will use that session by default if the parent object is not
+persistent with a session already.
0.2.7
- quoting facilities set up so that database-specific quoting can be
session = sessionlib.object_session(instance)
if session is None:
- raise exceptions.InvalidRequestError("Parent instance %s is not bound to a Session; lazy load operation of attribute '%s' cannot proceed" % (instance.__class__, self.key))
+ try:
+ session = mapper.object_mapper(instance).get_session()
+ except exceptions.InvalidRequestError:
+ raise exceptions.InvalidRequestError("Parent instance %s is not bound to a Session, and no contextual session is established; lazy load operation of attribute '%s' cannot proceed" % (instance.__class__, self.key))
# if we have a simple straight-primary key load, use mapper.get()
# to possibly save a DB round trip
import unittest, sys, os
from sqlalchemy import *
import sqlalchemy.exceptions as exceptions
-
+from sqlalchemy.ext.sessioncontext import SessionContext
from tables import *
import tables
{'user_id' : 7, 'addresses' : (Address, [{'address_id' : 1}])},
)
+ def testbindstosession(self):
+ ctx = SessionContext(create_session)
+ m = mapper(User, users, properties = dict(
+ addresses = relation(mapper(Address, addresses, extension=ctx.mapper_extension), lazy=True)
+ ), extension=ctx.mapper_extension)
+ q = ctx.current.query(m)
+ u = q.selectfirst(users.c.user_id == 7)
+ ctx.current.expunge(u)
+ self.assert_result([u], User,
+ {'user_id' : 7, 'addresses' : (Address, [{'address_id' : 1}])},
+ )
+
def testorderby(self):
m = mapper(Address, addresses)