nodes: 0, module; 1, function_definition; 2, function_name:sorting; 3, parameters; 4, block; 5, identifier:self; 6, expression_statement; 7, if_statement; 8, return_statement; 9, comment:"""Return fields to sort by including sort name for SQLAlchemy and row
          sort parameter for other ORMs
  
          :return list: a list of sorting information
  
          Example of return value::
  
              [
                  {'field': 'created_at', 'order': 'desc'},
              ]
  
          """; 10, call; 11, block; 12, list; 13, attribute; 14, argument_list; 15, expression_statement; 16, for_statement; 17, return_statement; 18, attribute; 19, identifier:get; 20, string; 21, assignment; 22, identifier:sort_field; 23, call; 24, block; 25, identifier:sorting_results; 26, identifier:self; 27, identifier:qs; 28, string_content:sort; 29, identifier:sorting_results; 30, list; 31, attribute; 32, argument_list; 33, expression_statement; 34, if_statement; 35, if_statement; 36, expression_statement; 37, expression_statement; 38, expression_statement; 39, subscript; 40, identifier:split; 41, string; 42, assignment; 43, comparison_operator:field not in self.schema._declared_fields; 44, block; 45, comparison_operator:field in get_relationships(self.schema); 46, block; 47, assignment; 48, assignment; 49, call; 50, attribute; 51, string; 52, string_content:,; 53, identifier:field; 54, call; 55, identifier:field; 56, attribute; 57, raise_statement; 58, identifier:field; 59, call; 60, raise_statement; 61, identifier:field; 62, call; 63, identifier:order; 64, conditional_expression:'desc' if sort_field.startswith('-') else 'asc'; 65, attribute; 66, argument_list; 67, identifier:self; 68, identifier:qs; 69, string_content:sort; 70, attribute; 71, argument_list; 72, attribute; 73, identifier:_declared_fields; 74, call; 75, identifier:get_relationships; 76, argument_list; 77, call; 78, identifier:get_model_field; 79, argument_list; 80, string; 81, call; 82, string; 83, identifier:sorting_results; 84, identifier:append; 85, dictionary; 86, identifier:sort_field; 87, identifier:replace; 88, string; 89, string; 90, identifier:self; 91, identifier:schema; 92, identifier:InvalidSort; 93, argument_list; 94, attribute; 95, identifier:InvalidSort; 96, argument_list; 97, attribute; 98, identifier:field; 99, string_content:desc; 100, attribute; 101, argument_list; 102, string_content:asc; 103, pair; 104, pair; 105, string_content:-; 106, call; 107, identifier:self; 108, identifier:schema; 109, call; 110, identifier:self; 111, identifier:schema; 112, identifier:sort_field; 113, identifier:startswith; 114, string; 115, string; 116, identifier:field; 117, string; 118, identifier:order; 119, attribute; 120, argument_list; 121, attribute; 122, argument_list; 123, string_content:-; 124, string_content:field; 125, string_content:order; 126, string:"{} has no attribute {}"; 127, identifier:format; 128, attribute; 129, identifier:field; 130, string:"You can't sort on {} because it is a relationship field"; 131, identifier:format; 132, identifier:field; 133, attribute; 134, identifier:__name__; 135, identifier:self; 136, identifier:schema
code: def sorting(self):
          """Return fields to sort by including sort name for SQLAlchemy and row
          sort parameter for other ORMs
  
          :return list: a list of sorting information
  
          Example of return value::
  
              [
                  {'field': 'created_at', 'order': 'desc'},
              ]
  
          """
          if self.qs.get('sort'):
              sorting_results = []
              for sort_field in self.qs['sort'].split(','):
                  field = sort_field.replace('-', '')
                  if field not in self.schema._declared_fields:
                      raise InvalidSort("{} has no attribute {}".format(self.schema.__name__, field))
                  if field in get_relationships(self.schema):
                      raise InvalidSort("You can't sort on {} because it is a relationship field".format(field))
                  field = get_model_field(self.schema, field)
                  order = 'desc' if sort_field.startswith('-') else 'asc'
                  sorting_results.append({'field': field, 'order': order})
              return sorting_results
  
          return []