How to correctly implement upshot's deleteEntity function on a child record

392 Views Asked by At

I have a Parent Child table structure.

I am trying to delete a child record. Here is my Simplified View Model.

MyNameSpace.ParentViewModel = function () {
    var self = this;
    self.dataSource = upshot.dataSources.GetRecords.refresh();
    self.jobs = self.dataSource.getEntities();

    self.removeChild1 = function (child) {
        $.each(self.jobs(), function() {
            this.JobStep.remove(jobStep);
        });
    };

    self.removeChild2 = function (child) {
        self.dataSource.deleteEntity(child);
    };
};

MyNameSpace.Parent = function (data) {
    var self = this;

    self.Id = ko.observable(data.Id);
    self.SomeProperty = ko.observable(data.SomeProperty);

    upshot.addEntityProperties(self, "Parent:#MyNameSpace.Models");
};

MyNameSpace.Child = function (data) {
   var self = this;

    self.Id = ko.observable(data.Id);
    self.ParentId = ko.observable(data.ParentId);
    self.Parent = ko.observable(data.Parent ? new MyNameSpace.Parent(data.Parent) : null);
    self.SomeChildProperty = ko.observable(data.SomeChildProperty );
    upshot.addEntityProperties(self, "Child:#MyNameSpace.Models");
};

When I try to delete a child record using removeChild1 I get the error:

Use 'deleteEntity' to delete entities from your array.  Destructive delete is not yet implemented.

When I try to delete a child record using removeChild2 I get an error:

'Entity not cached in data context. '

Obviously in the first version I am referencing the child record's ObservableArray collection and removing it from there. The correct object is removed but the non-implementation error kills it.

In the second version I am using upshot and EF magic and I'm not sure what is going wrong.

Any ideas?

0

There are 0 best solutions below