Hi.

I have an inheritance hierarchy on the form, C inherits B (with single table inheritance), B inherits A (with joined table inheritance).

The next query works perfectly:

session.query(C)\
    .join(C.related_objects)
    .filter( ... )  # Unrelated filtering conditions

as the resulting SQL does the join between the tables for A.__tablename__ and B.__tablename__, and filters B.__tablename__ using the discriminator column in the WHERE.

However, I need to do this:

session.query(func.sum(RelatedTable.value))\
    .select_from(C)\
    .join(C.related_objects)\
    .filter( ... )\  # Unrelated filtering conditions
    .one()

While the select_from() still does correctly the A/B join, the filtering condition is missing, so select_from(C) becomes the same as select_from(B).

I'm getting the right result using a explicit filter condition "filter(C.discriminator == C_DISCRIMINATOR)", but I guess I'm missing something.

Is this a kind of special case where some extra syntax is required? I didn't find anything relevant in the docs, neither in inheritance nor select_from() parts.

Thanks in advance.

Julio.

--
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 http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to