interpret a Query in Query as aliased(ent, q.subquery()) ?

Issue #2847 wontfix
Michael Bayer
repo owner created an issue

Basically, if you were to say sess.query(some_query).join(some_other_query) it would act like this:

from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()

class A(Base):
    __tablename__ = 'a'

    id = Column(Integer, primary_key=True)
    bs = relationship("B")

class B(Base):
    __tablename__ = 'b'

    id = Column(Integer, primary_key=True)
    a_id = Column(Integer, ForeignKey(''))

e = create_engine("sqlite://", echo=True)

sess = Session(e)

sess.add_all([B()](A(bs=[B(),)), A(bs=[B()](B()))])

def foo_thing(q):
    ent = q.column_descriptions[0](0)['expr']('expr')
    return aliased(ent, q.subquery())

q1 = sess.query(A)
q2 = sess.query(B)

print sess.query(foo_thing(q1)).join(foo_thing(q2)).all()

Comments (3)

  1. Log in to comment