sqlalchemy query 获取已经join过的表/ 获取query所属的model

  • 获取已经join过的表,以避免重复join
joined_list = [x.class_ for x in query._join_entities]

  • 获取query所在的model
 model = query.column_descriptions[0]['type']