def fk_to_one(f_key): """ Translate a foreign key name. """ # LOG.debug('f_key: ' + str(f_key)) local_columns = [] for fkc in f_key.foreign_key_columns: # LOG.debug('fkc: ' + str(fkc)) local_columns.append(fkc.fk_column_obj) local_columns.sort(key=lambda x: x.ordinal_position) out = "" for col in local_columns: LOG.debug('col.name: ' + str(col.name)) lname = name_translations.CapitalizedWords_to_py_name(col.name) LOG.debug('lname: ' + str(lname)) if lname.endswith('_name') or lname.endswith('_id'): out += name_translations.trunc_from_last_underscore(lname) else: out += lname out += "_" out = out[:-1] LOG.debug('out: ' + str(out)) existing = [col.py_name for col in f_key.table.columns] LOG.debug('existing: ' + str(existing)) if out in existing: out += "_obj" LOG.debug('out: ' + out) return out
def fk_to_one(f_key): """ Translate a foreign key name. The assumption is that a composite key is ordered, with the rightmost key being the distinguishing factor. i.e: schema_db_column is actually just column. """ # LOG.debug('f_key: ' + str(f_key)) local_columns = [] for fkc in f_key.foreign_key_columns: # LOG.debug('fkc: ' + str(fkc)) # LOG.debug('fkc.fk_column: ' + str(fkc.fk_column)) local_columns.append(fkc.fk_column_obj) local_columns.sort(key=lambda x: x.ordinal_position) out = "" for col in local_columns: lname = col.py_name.lower() if lname.endswith('_name') or lname.endswith('_id'): out = name_translations.trunc_from_last_underscore(col.py_name) else: out = col.py_name existing = [col.py_name for col in f_key.table.columns] if out in existing: out += "_obj" # LOG.debug('out: ' + out) return out