On May 25, 2013, at 11:29 AM, Michael Bayer <[email protected]> wrote:
> > On May 25, 2013, at 10:56 AM, Michael Bayer <[email protected]> wrote: > >> >> >> SQLAlchemy can do it, if you set up a full "with_polymorphic" join of all >> the tables, then use a CASE statement against all the tables to determine >> the discriminator. > > Here's that (I'll admit I'm surprised it works): you can do that just per-query too, without modifying __mapper__ at all (0.8 recommended): # left outer join all the tables pu = select([A.__table__, B.__table__, C.__table__, D.__table__, case([(B.id != None, "b"), (C.id != None, "c"), (D.id != None, "d")], else_=literal("a")).label('type') ], use_labels=True).select_from( A.__table__.outerjoin(B.__table__). outerjoin(C.__table__).outerjoin(D.__table__) ).alias() sess = Session(e) A_all = with_polymorphic(A, '*', selectable=pu, polymorphic_on=pu.c.type) print sess.query(A_all).all() -- 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
