original_docstring: Return values from child data that exist in the foreign_tbl transformed into foreign key values
  
      Args:
          session: A sqlalchemy session
          foreign_tbl: The foreign table mapping child data references
          foreign_key: The name of the column containing foreign key values
          foreign_value: The name of the column containing values to match with child data
          child_data: A list of data with values contained in foreign value
  
      Returns:
           A list of values from the foreign key column that correspond to child data's relationship to the foreign values
      
docstring: Return values from child data that exist in the foreign_tbl transformed into foreign key values
docstring_tokens: Return values from child data that exist in the foreign_tbl transformed into foreign key values
code: def values_to_foreign_key(session, foreign_tbl, foreign_key, foreign_value, child_data):
      """Return values from child data that exist in the foreign_tbl transformed into foreign key values
  
      Args:
          session: A sqlalchemy session
          foreign_tbl: The foreign table mapping child data references
          foreign_key: The name of the column containing foreign key values
          foreign_value: The name of the column containing values to match with child data
          child_data: A list of data with values contained in foreign value
  
      Returns:
           A list of values from the foreign key column that correspond to child data's relationship to the foreign values
      """
      # past 999 the SQLite backend raises a "too many variables warning". Here, we presume we don't have >999 unique
      # values in child_data. Rather, presume we have < 999 unique values and take a set of the data.
      set_data = set()
      if len(child_data) > 999:
          set_data = set(child_data)
      if type(foreign_tbl) == sqlalchemy.sql.selectable.Alias:
          conversion_dict = _values_to_foreign_key(session, foreign_tbl, foreign_key, foreign_value,
                                                   set_data or child_data)
          return [conversion_dict[i] for i in child_data]
      else:
          key_column = [getattr(foreign_tbl, foreign_key)]
          if isinstance(child_data, dict):
              composite_fd = True  # Composite functional dependency, two+ columns required to identify unique key
              value_columns = [getattr(foreign_tbl, val) for val in child_data.keys()]
              keys = list(child_data.keys())
              filters = [value_columns[i].in_(child_data[keys[i]]) for i in range(len(keys))]
          else:
              composite_fd = False
              value_columns = [getattr(foreign_tbl, foreign_value)]
              filters = [value_columns[0].in_(set_data or child_data)]
  
          rows = session.query(*key_column, *value_columns).distinct().filter(*filters).all()
  
          if composite_fd:
              nested_conversion_dict = NestedDict()
              for r in rows:
                  # multi-valued key with the foreign key as the value
                  nested_conversion_dict[[col for col in r[1:]]] = r[0]
  
              # Generate a list of lists with the values in each row of child data
              # These values form keys for the foreign keys stored in the nested_conversion_dict which is returned
              conversion_keys = []
              length = len(child_data[list(child_data.keys())[0]])
              for i in range(length):
                  conversion_keys.append([child_data[k][i] for k in child_data.keys()])
              return [nested_conversion_dict[k] for k in conversion_keys]
          else:
              conversion_dict = {getattr(row, foreign_value): getattr(row, foreign_key) for row in rows}
              return [conversion_dict[i] for i in child_data]
code_tokens: def values_to_foreign_key ( session , foreign_tbl , foreign_key , foreign_value , child_data ) : set_data = set ( ) if len ( child_data ) > 999 : set_data = set ( child_data ) if type ( foreign_tbl ) == sqlalchemy . sql . selectable . Alias : conversion_dict = _values_to_foreign_key ( session , foreign_tbl , foreign_key , foreign_value , set_data or child_data ) return [ conversion_dict [ i ] for i in child_data ] else : key_column = [ getattr ( foreign_tbl , foreign_key ) ] if isinstance ( child_data , dict ) : composite_fd = True value_columns = [ getattr ( foreign_tbl , val ) for val in child_data . keys ( ) ] keys = list ( child_data . keys ( ) ) filters = [ value_columns [ i ] . in_ ( child_data [ keys [ i ] ] ) for i in range ( len ( keys ) ) ] else : composite_fd = False value_columns = [ getattr ( foreign_tbl , foreign_value ) ] filters = [ value_columns [ 0 ] . in_ ( set_data or child_data ) ] rows = session . query ( * key_column , * value_columns ) . distinct ( ) . filter ( * filters ) . all ( ) if composite_fd : nested_conversion_dict = NestedDict ( ) for r in rows : nested_conversion_dict [ [ col for col in r [ 1 : ] ] ] = r [ 0 ] conversion_keys = [ ] length = len ( child_data [ list ( child_data . keys ( ) ) [ 0 ] ] ) for i in range ( length ) : conversion_keys . append ( [ child_data [ k ] [ i ] for k in child_data . keys ( ) ] ) return [ nested_conversion_dict [ k ] for k in conversion_keys ] else : conversion_dict = { getattr ( row , foreign_value ) : getattr ( row , foreign_key ) for row in rows } return [ conversion_dict [ i ] for i in child_data ]
short_docstring: Return values from child data that exist in the foreign_tbl transformed into foreign key values
short_docstring_tokens: Return values from child data that exist in the foreign_tbl transformed into foreign key values
comment: """Return values from child data that exist in the foreign_tbl transformed into foreign key values
  
      Args:
          session: A sqlalchemy session
          foreign_tbl: The foreign table mapping child data references
          foreign_key: The name of the column containing foreign key values
          foreign_value: The name of the column containing values to match with child data
          child_data: A list of data with values contained in foreign value
  
      Returns:
           A list of values from the foreign key column that correspond to child data's relationship to the foreign values
      """$SEP$# past 999 the SQLite backend raises a "too many variables warning". Here, we presume we don't have >999 unique$SEP$# values in child_data. Rather, presume we have < 999 unique values and take a set of the data.$SEP$# Composite functional dependency, two+ columns required to identify unique key$SEP$# multi-valued key with the foreign key as the value$SEP$# Generate a list of lists with the values in each row of child data$SEP$# These values form keys for the foreign keys stored in the nested_conversion_dict which is returned