Denis S. Otkidach wrote: > > I use declarative to define database scheme, and binds parameter to > session constructed from several metadata tables lists. And I have a > problem with inherited models, where table is represented as Join > object: get_bind() method doesn't find an engine. A quick-n-dirty > solution I use is: > > class Session(orm.session.Session): > > def get_bind(self, mapper, clause=None): > from sqlalchemy.orm.util import _class_to_mapper > if mapper is not None and clause is None: > c_mapper = _class_to_mapper(mapper) > if hasattr(c_mapper, 'mapped_table'): > clause = mapper.mapped_table > return orm.session.Session.get_bind(self, mapper, clause) > > Is it a bug in SQLAlchemy or I use it inapropriately? What is correct > solution?
if you're using bound metadata, the Session will use the binds associated with each table automatically. it doesn't matter if a mapper is mapped to a join, a join object will find a bind based on the tables it joins. if you are mapped specifically to a select() object, I noticed that the select is only going to locate the bind from the first selectable in the JOIN list, which might be your problem. this should be improved. the best way to go is to just bind the session directly to the engine or engines needed, using the "bind" or "binds" arguments. i don't bind metadata to engines in any case when using the ORM. bound metadata has also been downplayed very much in the documentation in recent months. > > > --~--~---------~--~----~------------~-------~--~----~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---