Awesome ultra-speedy reply!. I thought I might have to tell the mapper about how to join. I will try that approach.
The "query(Country).filter(Country.id==CountrySynonym.country_id)" doesn't work for me because I want to do an outer join. Thanks for the documentation link. I shall begin reading. :) Kind Regards Crispin Wellington On Mar 27, 3:58 am, Michael Bayer <[EMAIL PROTECTED]> wrote: > On Mar 26, 11:46 pm, Crispin Wellington <[EMAIL PROTECTED]> > wrote: > > > > > > > select * from countries left join country_synonyms; > > > Here are my attempts and their results: > > > >>> Session.query(Country).join(CountrySynonym).all() > > InvalidRequestError: Mapper 'Mapper|Country|countries' has no property > > '<class 'helloworld.model.CountrySynonym'>' > > > >>> Session.query(Country,CountrySynonym).join(CountrySynonym).all() > > > InvalidRequestError: Mapper 'Mapper|Country|countries' has no property > > '<class 'helloworld.model.CountrySynonym'>' > > > >>> Session.query(Country).join(CountrySynonym.country_id).all() > > > AttributeError: 'ColumnProperty' object has no attribute > > '_is_self_referential' > > > And so on... > > query.join() only joins on relations that you set up between mappers. > so if you set up your mappers like: > > mapper(Country, countries, properties={ > 'synonyms':relation(CountrySynonym) > > }) > > mapper(CountrySynonym, country_synonyms) > > then your join would just be: > > query(Country).join('synonyms') > > if you want to join tables together where you haven't told your > mappers about their relationship (or you want to join in some other > way besides whats configured), then you use the Table objects again, > but you can still use them with Query via select_from() > > query(Country).select_from(countries.join(country_synonyms))... > > With a regular inner join like you're doing, theres also just setting > it up in the WHERE criterion: > > query(Country).filter(Country.id==CountrySynonym.country_id).... > > > All the docs use a Table() based approach like > > "sql.execute(countries.join(country_synonyms)..." but I want to use > > the Mapped objects as that's what I'm using everywhere else. I've > > found the docs on sqlalchemy to focus on the Table() and engine based > > interfaces, but the docs focusing on objects and sessions leave a lot > > of guessing. > > Plenty of docs on the subject in the ORM tutorial. For examples of > query.join(), see: > > http://www.sqlalchemy.org/docs/04/ormtutorial.html#datamapping_joins > > other important ORM chapters are "Mapper Configuration" and "Using the > Session". --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---