'Return a dictionary of {field_name: (field_name_other_table, other_table)}
representing all relationships to the given table.'

def get_relations(self, cursor, table_name):

    cursor.execute("\n                                                SELECT    c2.relname,    a1.attname,    a2.attname\n                                                FROM    pg_constraint    con\n                                                LEFT    JOIN    pg_class    c1    ON    con.conrelid    =    c1.oid\n                                                LEFT    JOIN    pg_class    c2    ON    con.confrelid    =    c2.oid\n                                                LEFT    JOIN    pg_attribute    a1    ON    c1.oid    =    a1.attrelid    AND    a1.attnum    =    con.conkey[1]\n                                                LEFT    JOIN    pg_attribute    a2    ON    c2.oid    =    a2.attrelid    AND    a2.attnum    =    con.confkey[1]\n                                                WHERE    c1.relname    =    %s\n                                                                AND    con.contype    =    'f'", [table_name])
    relations = {}
    for row in cursor.fetchall():
        relations[row[1]] = (row[2], row[0])
    return relations
