I thought it should work too, but I'm getting:

    "InvalidRequestError: Could not find a FROM clause to join from.  Tried 
joining to <class 'app.models.Person2Topic'>, but got: Can't find any 
foreign key relationships between 'message' and 'person_2_topic'."

If i have time this weekend I'll look into this.  If i don't find a bug in 
my code, I'll post a reproducable test-case on github.



On Friday, April 26, 2013 7:18:24 PM UTC-4, Michael Bayer wrote:
>
>
> On Apr 26, 2013, at 7:10 PM, Jonathan Vanasco 
> <jona...@findmeon.com<javascript:>> 
> 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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
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