diff --git a/src/javascripts/ng-admin/Crud/form/FormController.js b/src/javascripts/ng-admin/Crud/form/FormController.js index ca7bcbb2..6fdbd07a 100644 --- a/src/javascripts/ng-admin/Crud/form/FormController.js +++ b/src/javascripts/ng-admin/Crud/form/FormController.js @@ -26,6 +26,9 @@ define(function () { this.$scope.view = view; this.$scope.entity = this.entity; + // in case of entity identifier being modified + this.origEntityId = this.$scope.entry.values[this.entity.identifier().name()] + $scope.$on('$destroy', this.destroy.bind(this)); }; @@ -34,7 +37,7 @@ define(function () { form = this.form, entry = this.$scope.entry, fields = this.view.getFields(), - identifierField = this.view.getEntity().identifier(), + identifierField = this.entity.identifier(), mappedObject, field, i, @@ -96,7 +99,7 @@ define(function () { notification = this.notification; progression.start(); this.UpdateQueries - .updateOne(this.view, entry) + .updateOne(this.view, entry, this.origEntityId) .then(function () { progression.done(); notification.log('Changes successfully saved.', {addnCls: 'humane-flatty-success'}); diff --git a/src/javascripts/ng-admin/Crud/repository/UpdateQueries.js b/src/javascripts/ng-admin/Crud/repository/UpdateQueries.js index 0fe29dd3..781ab87a 100644 --- a/src/javascripts/ng-admin/Crud/repository/UpdateQueries.js +++ b/src/javascripts/ng-admin/Crud/repository/UpdateQueries.js @@ -18,13 +18,14 @@ define(function (require) { * Update an entity * Put the data to the API to create the new object * - * @param {View} view the formView related to the entity - * @param {Object} rawEntity the entity's object + * @param {View} view the formView related to the entity + * @param {Object} rawEntity the entity's object + * @param {String} origEntityId if entity identifier is modified * * @returns {promise} the updated object */ - UpdateQueries.prototype.updateOne = function (view, rawEntity) { - var entityId = rawEntity[view.getEntity().identifier().name()]; + UpdateQueries.prototype.updateOne = function (view, rawEntity, origEntityId) { + var entityId = origEntityId || rawEntity[view.getEntity().identifier().name()]; // Get element data return this.Restangular