Hi!
SQLAlchemy is really awesome (I really love it)
and I am still working on the RUM web frontend for it.
I have the problem, that I would like to make some nested join:
query=session.query(Address)
query=query.join(User, Address.user)
query=query.join(Group, User.group)
Is it legal to the join this way?
The clauses seem to be duplicated:
SELECT addresses.id AS addresses_id, addresses.email_address AS
addresses_email_address, addresses.user_id AS addresses_user_id
FROM addresses
JOIN users ON users.id = addresses.user_id
JOIN users ON users.id = addresses.user_id
JOIN groups ON groups.id = users.group_id
JOIN groups ON groups.id = users.group_id
I attach a full example to this mail.
I got the same behaviour with all versions I tried (0.5.8 (the example is for
0.6.x), 0.6.1, and 0.6.3.
Thank you very much in advance.
Michael
-------------------------------------------
Michael Brickenstein
Mathematisches Forschungsinstitut Oberwolfach gGmbH
Schwarzwaldstr. 9 - 11
77709 Oberwolfach
Tel.: 07834/979-31
Fax: 07834/979-38
from sqlalchemy import *
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import ForeignKey
from sqlalchemy.orm import relationship, backref, sessionmaker
Base = declarative_base()
metadata = Base.metadata
class User(Base):
__tablename__ = 'users'
id = Column(Integer, primary_key=True)
name = Column(String)
group_id=Column(Integer, ForeignKey('groups.id'))
class Address(Base):
__tablename__ = 'addresses'
id = Column(Integer, primary_key=True)
email_address = Column(String, nullable=False)
user_id = Column(Integer, ForeignKey('users.id'))
user = relationship(User, backref=backref('addresses', order_by=id))
class Group(Base):
__tablename__ = 'groups'
id = Column(Integer, primary_key=True)
name = Column(String)
users= relationship(User, backref='group')
engine = create_engine('sqlite:///:memory:', echo=True)
metadata = MetaData(bind=engine)
metadata.create_all(engine)
Session = sessionmaker(bind=engine)
session = Session()
query=session.query(Address)
query=query.join(User, Address.user)
query=query.join(Group, User.group)
print str(query)
--
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.