Hi there, Sorry for not commenting on this sooner, I've been on a vacation.
The patch you're using imports the threadlocal mod, so you don't need to create/use explicit sessions. For flushing, you use sqlalchemy.objectstore.flush() - or just forget about it and let TG handle it automatically at the end of the request. I have a similar situation, I have a model defined in a module not related to my TG project. That model uses a DynamicMetadata, stored in a module-variable called __meta__. In model.py in my TG project, I do this: from someotherproject.model.jobs import __meta__ as jobsmeta jobsmeta.connect(__engine__) from someotherproject.model.jobs import * __engine__ is, as you know, the PackageEngine instance created at the top of model.py This allows me to do "from model import *" in controllers and have access to all model classes, wether they're defined in TG's model.py or in my other project. I think your solution does the same thing essentially. All of my model-classes use the same database engine (they all live in the same db). Is this different in your case? I.e. are you connecting to multiple dbs? Arnar On 6/27/06, Randall <[EMAIL PROTECTED]> wrote: > > I've made some progress in this area and wanted to share. My SA > objects use DynamicMetaData, so an engine has to be mapped to them. TG > uses a threadlocal context which provides a default session accessible > via sqlalchemy.objectstore. This is not the objectstore from SA 1. > DynamicMetaData instances are connected to an engine via their connect > method. Since we're in a threadlocal context, each spawned thread has > to make this connection. In my situation I've got three groups of data > objects using three different DynamicMetaData instances and I can use > cherrypy's server.on_start_thread_list to schedule execution of these > connections on a thread's initialization as shown below: > > engine = sqlalchemy.create_engine(cns) > > def connectKlass(thread_index): > for klass in (Tinwsys, User, Project): > class_mapper(klass).mapped_table.metadata.connect(engine) > > cherrypy.server.on_start_thread_list.append(connectKlass) > > class PlanReviewController(controllers.RootController, > RESTfulController): > > As you see, I put the connection code above my controller. I'll > probably place it above my root controller. I'm currently creating my > own engine, but I'll see if this works with TG's PackageEngine. > > Feedback is welcome. > > Randall > .... > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "TurboGears" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/turbogears -~----------~----~----~----~------~----~------~--~---

