mix of multiple joins and multiple tables and multiple columns in python orm

Solutions on MaxInterview for mix of multiple joins and multiple tables and multiple columns in python orm by the best coders in the world

showing results for - "mix of multiple joins and multiple tables and multiple columns in python orm"
Isabella
29 Aug 2020
1query_result = session.query(models.Table1.col1.label('table1_col1'),
2                             models.Table1.col2.label('table1_col2'),
3                             models.Table2.col3.label('table2_col3'),
4                             models.Table2.col4.label('table2_col4'),
5                             models.Table3.col5.label('table3_col5'),
6                             models.Table3.col6.label('table3_col6'),
7                             models.Table4.col7.label('table4_col7'),
8                             models.Table5.col8.label('table5_col8')).join(
9  models.Table6, and_(models.Table6.<col>==models.Table2.<col>,
10                      models.Table2.<col>.in_(<list_of_values>)), isouter=False).join(
11  models.Table1, models.Table1.<col>==models.Table6.<col>, isouter=False).join(
12  models.Table3, and_(models.Table3.<col>==models.Table2.<col>,
13                      models.Table3.<col>==models.Table1.<col>), isouter=False).join(
14  models.Table4, models.Table4.<col>==models.Table3.<col>,
15  isouter=True).join(models.Table5,models.Table5.<col>==models.Table3.<col>,
16                     isouter=True)
17result = list(set(query_result.all()))