python

Join models or tables query Sqlalchemy

Joining tables query in Sqlalchemy can be written as below

#JOINING TABLE (User and Address)
self.session.query(
    User.id,
    User.first_name,
    User.last_name,
    Address.city,
    Address.State
).join(
    Address, User.id == Address.user_id
).filter(
    Address.city.like('new%'))
).all()
Was this helpful?