mmmm yeah. OK we only have limited support for that concept right now using of_type(), which currently only supports one type, not a list. so it would be query(Company).join(Company.employees.of_type(Engineer)). In theory of_type() could support a list, but that isnt built right now. So to really get the full SQL you're looking for you'd have to go "old school" and use the table objects here, like:
session .query (Company ).select_from (company_table.join(employees_table).outerjoin(engineers_table, <onclause>).outerjoin(managers_table, <onclause>)).<everything else>. you'll actually get a better query from the above since it won't wrap the engineer/manager stuff in a subquery. On Jun 10, 2009, at 8:38 PM, David Gardner wrote: > > I was wondering if there was a way to use with_polymorphic() on a > joined > table. > > For instance using the Company->Employees relationship in the > example on > http://www.sqlalchemy.org/docs/05/mappers.html#mapping-class-inheritance-hierarchies > > if I wanted to query for a company, and eagerload the employees and > eagerly join the engineers and managers tables I would think to do > something like: > > session.query(Company).join(Company.employees).\ > options(contains_eager(Company.employees)).\ > with_polymorphic([Engineer, Manager]).\ > filter(Company.name=='test').first() > > However this doesn't work I get: > > /usr/lib/pymodules/python2.5/sqlalchemy/orm/query.pyc in generate(fn, > *args, **kw) > 49 self = args[0]._clone() > 50 for assertion in assertions: > ---> 51 assertion(self, fn.func_name) > 52 fn(self, *args[1:], **kw) > 53 return self > > /usr/lib/pymodules/python2.5/sqlalchemy/orm/query.pyc in > __no_clauseelement_condition(self, meth) > 279 if self._order_by: > 280 raise sa_exc.InvalidRequestError("Query.%s() being > called on a Query with existing criterion. " % meth) > --> 281 self.__no_criterion_condition(meth) > 282 > 283 def __no_statement_condition(self, meth): > > /usr/lib/pymodules/python2.5/sqlalchemy/orm/query.pyc in > __no_criterion_condition(self, meth) > 269 self._limit is not None or self._offset is not > None or \ > 270 self._group_by: > --> 271 raise sa_exc.InvalidRequestError("Query.%s() being > called on a Query with existing criterion. " % meth) > 272 > 273 self._from_obj = () > > InvalidRequestError: Query.with_polymorphic() being called on a Query > with existing criterion. > > -- > David Gardner > Pipeline Tools Programmer > Jim Henson Creature Shop > [email protected] > > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
