def get_field_with_path(model, name, return_remote_proxy_attr=True):
 path = []
 if isinstance(name, string_types):
  current_model = model
  value = None
  for attribute in name.split('.'):
   value = getattr(current_model, attribute)
   if is_association_proxy(value):
    relation_values = value.attr
    if return_remote_proxy_attr:
     value = value.remote_attr
   else:
    relation_values = [value]
   for relation_value in relation_values:
    if is_relationship(relation_value):
     current_model = relation_value.property.mapper.class_
     table = current_model.__table__
     if need_join(model, table):
      path.append(relation_value)
  attr = value
 else:
  attr = name
  if (isinstance(attr, InstrumentedAttribute) or is_association_proxy(attr)):
   columns = get_columns_for_field(attr)
   if (len(columns) > 1):
    raise Exception(('Can only handle one column for %s' % name))
   column = columns[0]
   if need_join(model, column.table):
    path.append(column.table)
 return (attr, path)

def get_field_with_path ( model , name , return_remote_proxy_attr = True ) : path = [ ] if isinstance ( name , string_types ) : current_model = model value = None for attribute in name . split ( '.' ) : value = getattr ( current_model , attribute ) if is_association_proxy ( value ) : relation_values = value . attr if return_remote_proxy_attr : value = value . remote_attr else : relation_values = [ value ] for relation_value in relation_values : if is_relationship ( relation_value ) : current_model = relation_value . property . mapper . class_ table = current_model . __table__ if need_join ( model , table ) : path . append ( relation_value ) attr = value else : attr = name if ( isinstance ( attr , InstrumentedAttribute ) or is_association_proxy ( attr ) ) : columns = get_columns_for_field ( attr ) if ( len ( columns ) > 1 ) : raise Exception ( ( 'Can only handle one column for %s' % name ) ) column = columns [ 0 ] if need_join ( model , column . table ) : path . append ( column . table ) return ( attr , path )
resolve property by name and figure out its join path .