Apply the key format in toArray also to foreignKey indices