开发者

how to do a join in sqlalchemy session query?

I need to find the equivalent of this query in sqlalchemy.

SELECT u.user_id, u.user_name, c开发者_如何学JAVA.country FROM
table_user u , table_country c WHERE u.user_email = 'abc@def.com'

i tried this below code:

session.query(User).join(Country.country).filter(User.user_email == 'abc@def.com').first()

and this gave me below error :

  AttributeError: 'ColumnProperty' object has no attribute 'mapper'

can anyone give an example of join query with tables mapped to new class objects ?


Try this, assuming your User mapper has a relationship to Country configured.

user, country = session.query(User, Country.country).join(Country).filter(User.user_email == 'abc@def.com').first()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜