def need_join(model, table):
 return (table not in model._sa_class_manager.mapper.tables)

def need_join ( model , table ) : return ( table not in model . _sa_class_manager . mapper . tables )
check if join to a table is necessary .