Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Edit identity (primary key) field (#332 issue on GitHub) #334

Merged
merged 1 commit into from
Mar 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd use the simpler

this.entityId = entry[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