FYI: Upgraded to SQLalchemy 0.5.8 A class produces using __table__ instead of __tablename__ provides the field names as in the database, not as mapped in the joined objects (below: x1, x2). [example: I can use x3.job_id but task_id fails.] And trying to set columns in the derived class like:
class Action(Base): """ An OpenGroupare Task History Info entry """ __table__ = x3 object_id = Column('job_history_id') # object_id = Column('job_history.job_history_id') ALSO FAILS Produces the exception: Can't add additional column 'object_id' when specifying __table__ But (a) I want the aliased names and (b) previous post indicated I would have to alias the shared column [2]. Confused. [2] http://groups.google.com/group/sqlalchemy/browse_thread/thread/b0ce69e368b444dd/59edd004f450c6bd?lnk=raot > ------------------------------------------- > #!/usr/bin/python > import sys > from sqlalchemy import * > import sqlalchemy.orm > from sqlalchemy.ext.declarative import declarative_base > > engine = create_engine('postgres://o...@127.0.0.1/OGo', echo=True) > Base = declarative_base() > > class x1(Base): > __tablename__ = 'job_history' > id = Column('job_history_id', Integer, > Sequence('key_generator'), primary_key=True) > task_id = Column('job_id', Integer) > actor_id = Column('actor_id', Integer) > action = Column('action', String) > > class x2(Base): > __tablename__ = 'job_history_info' > _info_id = Column('job_history_info_id', Integer, > Sequence('key_generator'), primary_key=True) > comment = Column('comment', String) > _hist_id = Column('job_history_id', Integer, ForeignKey(x1.id)) > # ALSO WORKS _hist_id = Column('job_history_id', Integer, > ForeignKey('job_history.job_history_id')) > > x3 = sqlalchemy.orm.join(x1, x2) > > class Action(Base): > """ An OpenGroupare Task History Info entry """ > __table__ = x3 > > Session = sqlalchemy.orm.sessionmaker() > Session.configure(bind=engine) > db = Session() > > z = Action() > z.job_id = 1 > z.comment = 'TEST TEST TEST' > z.actor_id = 0 > z.action = 'test' > db.add(z) > > db.commit() > > query = db.query(Action).filter(Action.job_id == 1) > for a in query.all(): > print a.comment > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@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.