On Wed, 2010-02-03 at 10:55 -0500, Michael Bayer wrote:
> Adam Tauno Williams wrote:
> > x3 = join(x1, x2)
> join() here is:
> http://www.sqlalchemy.org/docs/reference/sqlalchemy/expressions.html#sqlalchemy.sql.expression.join
> it knows nothing about classes "x1" and "x2" and interprets them as text.
> You want here to be using:
> http://www.sqlalchemy.org/docs/reference/orm/query.html#sqlalchemy.orm.join
> if you upgrade to a recent 0.5 (highly recommended as 0.5.4 is ancient)
> the "orm.join" function will come into your imports via "from
> sqlalchemy.orm import *".
Ah, yep, that was it. Using sqlalchemy.orm.join produces a working
join -
Works
-------------------------------------------
#!/usr/bin/python
import sys
from sqlalchemy import *
import sqlalchemy.orm
from sqlalchemy.ext.declarative import declarative_base
engine = create_engine('postgres://[email protected]/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 [email protected].
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.