On Nov 28, 2011, at 5:20 PM, [email protected] wrote: > At the moment, it makes no difference whether I put: > > for c in session.query(Church).outerjoin(Minister): > print "<b>",c.name, "</b><br />" > for p in c.people: > print p.surname, "<br />" > > or > > for c in session.query(Church).outerjoin(Person): > print "<b>",c.name, "</b><br />" > for p in c.people: > print p.surname, "<br />" > > What do I need to do to restrict Person shown to Minister? > I had imagined in my naivete that merely creating the subclass would > do it :)
you need to make use of the relationship() that's been configured in order for the join to be aware of polymorphism - a join that is query(X).join(Y) only does a "dumb" join between foreign keys. You'd probably be looking for: query(Church).outerjoin(Church.people.of_type(Minister)) of_type() is introduced at http://www.sqlalchemy.org/docs/orm/inheritance.html#creating-joins-to-specific-subtypes though sort of specific to joined-table inheritance, works with single as well. These docs are still undergoing some reorganization and the inheritance section could use some modernization. -- 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.
