On May 10, 2007, at 12:05 PM, Chris Perkins wrote:

> if 0:
>     # This works fine:
>     pjoin = (T1_select.c.id==T2_select.c.parent_id) &
> (T1_select.c.ver==T2_select.c.parent_ver)
>     fks = [T1_select.c.id, T1_select.c.ver]
>
> else:
>     # But this does not:
>     pjoin = (T1.c.id==T2.c.parent_id) & (T1.c.ver==T2.c.parent_ver)
>     fks = [T1.c.id, T1.c.ver]
>
> m1.add_property('my_twos', relation(Two, primaryjoin=pjoin,
> foreign_keys=fks))
>

the second version is not going to work because you are expressing  
the joins and foreign keys in terms of the underlying tables, not the  
relations to which the mappers are bound (i.e. T1_select,  
T2_select).  so the mapper cant do anything with that (more  
specifically, it decides not to try and interpolate the columns into  
the corresponding columns on the selectable...since that doesnt  
really work for relationships between selectables that both include  
the same underlying tables).

it works when you have the foreign keys directly on the tables  
because the select()s you create propigate the constraints from their  
underlying selected tables into the appropriate constraints for that  
select object (and also know how to join each other).  i.e.:

 >>> [(f.column, f.parent) for f in T2_select.foreign_keys]
[('T1.id', 'T2_select.parent_id'), ('T1.ver', 'T2_select.parent_ver')]

 >>> T1_select.join(T2_select).onclause
"T1_select".id = "T2_select".parent_id AND "T1_select".ver =  
"T2_select".parent_ver

so that produces the same effective arguments you have in the first  
version.




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