Pregunta

I have a bulk insert screen which allows the user to insert products line by line.. Each product has it's own Units of measurement.

Here is my save changes Code:

save = function (product) {
var entitiesToSave = product.units().slice();

entitiesToSave.push(product);

var so = new breeze.SaveOptions({ allowConcurrentSaves: true })
            return manager.saveChanges([entitiesToSave],so)
                    .then(saveSucceeded)
                    .fail(saveFailed);
}

Once I try to save; I get this message:

The 'entities' parameter is optional or it must be an array where each element must be an entity

Modifying the code to:

save = function (product) {
var so = new breeze.SaveOptions({ allowConcurrentSaves: true })
            return manager.saveChanges([product,product.units()[0]],so)
                    .then(saveSucceeded)
                    .fail(saveFailed);
}

Works fine for one product unit.. However, I needed to save a specific product with all of it's units in one shot.. Any help is appreciated.

¿Fue útil?

Solución

For those who might have similar issue; I got it fixed by modifying the code to the following:

save = function (product) {
var entitiesToSave = new Array(product);

product.Units().forEach(function (Unit) {
              entitiesToSave.push(Unit);
});

var so = new breeze.SaveOptions({ allowConcurrentSaves: true })
            return manager.saveChanges(entitiesToSave,so)
                    .then(saveSucceeded)
                    .fail(saveFailed);
}

Regards to all.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top