updates keys and fixed relationship pivot field order