at first glance it seems like you need just session.query 
(Employee).join('managers').filter(mgr.c.age < 40) ?

oh, but the issue is that "managers" is self-referring and needs to  
be an alias ?

we have a "mini" feature in 0.4 so far which creates aliases, but its  
not quite what you want yet, it looks like:

session.query(Employee).filter_by(['managers'], age=40)

that will create an "anonymized" join to the same table.   this is  
using get_join() with the keyword "create_aliases" (which you can  
also try out.  for your stuff, you should be working with 0.4  
directly right now since youre on the "cutting edge").

But also, due to recent inclement weather, we want to try to expand  
out this feature from filter_by() into something that can use any  
operator.   this would look like...well..it would look like  
Class.prop == <whatever> .   *cue dramatic music*  since multiple  
class.prop==<whatevers> will combine together using AND semantics,  
they probably will have to create aliased joins.

so yeah, everyone's wanted that since version 0.1, so....now you'll  
all get it.

On Jul 11, 2007, at 4:56 PM, [EMAIL PROTECTED] wrote:

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