On Apr 26, 2013, at 7:10 PM, Jonathan Vanasco <[email protected]> wrote:

> Given
>       class Person:
>               id
>               
>       class Topic:
>               id
>       
>       class Person2Topic :
>               id 
>               topic_id  - fkeys topic(id)
>               person_id - fkeys person(id)
>       
>       class Message:
>               id
>               person_id_author - fkeys person(id)
>               topic_id - fkeys topic(id)
>       
>       
>       
> I wanted to select by joining the Person2Topic table directly, with a filter
> 
>       query( Message )\
>               join(  Person2Topic ,(
>                                       Message.topic_id == 
> Person2Topic.topic_id ,
>                                       Person2Topic.person_id = 1  
>               )
> 
> This generates errors, because sqlalchemy doesn't have an fkey on 
> Message.topic_id = Person2Topic.topic_id
>       
> i can only figure out how to do query by doing intermediary joins
> 
>       query( Message )\
>               join( Topic , ( Message.topic_id == Topic.id ) )\
>               join(  Person2Topic ,( Topic.id = Person2Topic.topic_id )\
>               filter( Person2Topic.person_id = 1 )
> 
> is it possible to do a select like I originally wanted ?

you can write out the join condition as you are (not sure what's the downside 
there), or if you're looking for a relationship() to do it you'd need to set up 
a primaryjoin + foreign_keys in the relationship() to join as you want.  I'm 
not sure what other options would be here.


-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to