TheMook
TheMook

Reputation: 1541

entityAspect.setDeleted() appears to remove the entity from the observableArray that it's in?

I thought the idea of entity.entityAspect.setDeleted() was to set a "deleted" flag on the entity but nothing else?

The problem is that I have an observableArray of entities, I call "setDeleted()" on one of them and my observableArray instantly reduces by one. When I subsequently call "saveChanges" with the observableArray of entities passed in as an argument the deleted entity is not present and that seems to stop the deletion being made permanent as the entity is still there when I refresh the page.

Am I missing a fundamental point here? My saveChanges method works fine for newly created entities and for changed entities, just not deleted ones as they never exist at the point that "saveChanges" is called!

    return manager.saveChanges(entities)
        .then(saveSucceeded)
        .fail(saveFailed);

Upvotes: 3

Views: 2358

Answers (1)

Jay Traband
Jay Traband

Reputation: 17052

Calling "setDeleted", does several things (per design).

1) It marks the entity as 'deleted', i.e. entityAspect.entityState becomes 'Deleted'.

2) The entity is removed from any navigation property arrays to which it belongs. i.e. if you delete an 'orderDetail', it will be removed from the parent 'orderDetails' collection along with any other navigation collections to which it belongs.

3) If the entity is 'saved' it gets actually deleted on the database and the entity on the client goes into a 'detached' state. (This means that you must either call EntityManager.saveChanges WITHOUT any parameters (in which case breeze sends all added/modified or deleted entities to the server) or you must explicitly pass in the 'deleted' entity, along with any other changes, to the saveChanges call.

My guess is that your 'observable' array is actually the value of a navigation property and you are explicitly calling saveChanges with this collection ( which will no longer includes the 'deleted' entity). Try just calling saveChanges() without any args.

Does this make sense?

Upvotes: 5

Related Questions