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
-~----------~----~----~----~------~----~------~--~---

Reply via email to