Hi everyone!

I am trying to use the contains_eager option on a simple polymorphic query 
that looks like:

class Superclass():
    common_relationship = relationship('Common', ...)
    discriminator_field = Column(String...)
    __mapper_args__ = {'polymorphic_identity': 'superclass', 
'polymorphic_on': discriminator_field}

class Subclass(Superclass):
    fields...

poly = with_polymorphic(Superclass, '*')
db.session.query(poly).options(contains_eager(poly.common_relationship)).
join(poly.common_relationship).filter(Common.id == 1).all()

This code throws an error when I execute the query:

sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) subquery uses 
ungrouped column "common.id" from outer query

Removing the contains_eager option and replacing it with a lazy or join 
option does solve the problem, but introduces overhead to my SQL query. 
What I am trying to achieve here is for the query to not perform two joins 
(once for the join to filter on, and once for the join to populate the 
poly.common_relationship field). Am I approaching this entirely wrong here?

Thanks in advance!

Jay

-- 
This e-mail is private and confidential and is for the addressee only. If 
misdirected, please notify us by telephone, confirming that it has been 
deleted from your system and any hard copies destroyed. You are strictly 
prohibited from using, printing, distributing or disseminating it or any 
information contained in it save to the intended recipient.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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.

Reply via email to