Lets say there are Employee, Engineer, Manager, etc whole tree, with 
Employee in the root; all levels do have instances and its 
polymorphical multitable inheritance.

Let's the Employee has attribute age - number, and manager - pointing 
to some other Employee.

how to get all Employees which have a manager of age less than 40?

a straight forward sql-like thing would look like:

mgr = tableEmployee.alias()
r = session.query( Employee).select( 
    (tableEmployee.c.manager_id == mgr.id) & (mgr.c.age < 40) )

but can i do something smarter... e.g. some .join, .filter or 
something similar?

The reason of talking about Property.get_join() here is that i am 
actualy creating the above clause on the run, autoconverting from an 
expression func (e.g. lambda self: self.manager.age<40). After lots 
of other machinery, i am using mapper.props[key].get_join() to 
guess/add the (implicit) join-conditions.

The property here is self-referential. 

If the mapper (Employee) is not polymorphic - e.g. none of the other 
subclasess exist - all is okay, get_join() returns something that i 
ClauseAdapt to use an aliased table instead the original:
   tblemployee.manager_id == tblempluyee.db_id 
-> tblemployee.manager_id == tblemployee_0123.db_id

But if the mapper is polymorphic, prop.get_join() returns the 
(mapper.select_table's) polymunion put on both sides:
   pu_employee.manager_id == pu_employee.db_id 
which my code does not recognise - its looking for tblemployee.db_id.

so the question is: is there any way to make the get_join() to not 
return polymunions on _both_ sides? i see they come from some  
ClauseAdaptor (many2one case) being applied...
And why it has to apply to both sides?

what i need is something like replacing only one side:
   pu_employee.manager_id == tblemployee.db_id
anyway, i can roll my own get_join() replacement, i am already 
workarounding the cache u have there, and having my own join_via...

(and back to the first question, the .join_to() and .join_via() finaly 
use the prop.get_join() - hence i dont see how to get out of the 
loop..)

btw are there any changes in these mechanics in the 0.4? 
i haven't looked there yet.

ciao
svil

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
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