Skip to content
This repository has been archived by the owner on May 9, 2020. It is now read-only.

Commit

Permalink
fix: Edit identity (primary key) field (marmelab#332 issue on GitHub)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vasia Korobkin committed Feb 27, 2015
1 parent b3c7b1a commit 65c5207
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/javascripts/ng-admin/Crud/form/FormController.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ define(function () {
this.view = view;
this.entity = this.view.getEntity();

// in case of entity identifier being modified
this.origEntityId = this.$scope.entry.values[this.entity.identifier().name()]

$scope.$on('$destroy', this.destroy.bind(this));
};

Expand All @@ -33,7 +36,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,
Expand Down Expand Up @@ -99,7 +102,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'});
Expand Down
9 changes: 5 additions & 4 deletions src/javascripts/ng-admin/Crud/repository/UpdateQueries.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 65c5207

Please sign in to comment.