On Jun 22, 2007, at 4:52 AM, SamDonaldson wrote:
> > Ok, so let me explain the problem we're facing. I'm using turbogears > with sqlalchemy. I run a custom query by supplying the SELECT string > to the engine and then execute() that. It returns back a list of > tuples. I'd like it to return a bunch of instances of A but I can't > seem to find the api to do that. Note that I'm not selecting > everything, just a few columns. So, I wrote my own constructor which > basically runs through the tuple list and constructs instances of > class A and then returns that list back to my controller. > > The problem is that when I'm exiting my controller, I find that I get > a duplicate key error because it seems like the controller in > turbogears tries to commit unsaved objects (the ones I manually > created for better access in my code). Why is this? How do I turn > this off? turbogears must be using the SessionContextExt with mappers, such that all new object instances get added to the contextual Session automatically. the behavior of this extension is described in the "plugins" chapter of the SQLAlchemy documentation. youd have to see how to disable this behavior in TG, though. also, the API to return instances is the Query object, described at http://www.sqlalchemy.org/docs/datamapping.html#datamapping_query . to load subsets of columns using ORM, use deferred columns: http://www.sqlalchemy.org/docs/ adv_datamapping.html#advdatamapping_properties_deferred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---