from sqlalchemy import Column, and_
from sqlalchemy import create_engine, Integer, String, Date, Enum
from sqlalchemy.orm import sessionmaker, relationship, remote, foreign
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.exc import DataError, IntegrityError
Base = declarative_base()
class Game(Base):
__tablename__ = 'game'
team = Column(String, primary_key=True, index=True)
opponent = Column(String, primary_key=True, index=True)
date = Column(Date, primary_key=True, index=True)
result = Column(Enum('win', 'loss', name='win_loss'), index=True)
points = Column(Integer)
opp = relationship(
'Game',
uselist=False,
lazy='joined',
primaryjoin=and_(
foreign(team) == remote(opponent),
foreign(opponent) == remote(team),
foreign(date) == remote(date)))
engine = create_engine('postgresql://buttons:buttons@localhost/ncaa', echo=True)
new_session = sessionmaker(engine)
# The following line produces a query like: select * from game
# The query does NOT contain a join.
new_session().query(Game).all()
The query on the last line off the example produces a simple "select * from
game" type query (the columns are spelled out of course). I was expecting
the lazy='joined' argument to result in a join. What am I doing wrong?
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.