Refactor get_referencing_foreign_keys