0
votes

When I am calling rejectChanges() on an entity that has a non-scalar property that is a complex type it appears it is deleting all of those complex types -

metadataStore.addEntityType({
    shortName: "GrandParent",
    namespace: "Product",
    dataProperties: {
        id: { dataType: "String", isPartOfKey: true },
        someValues: { complexTypeName: "parentValue:#Product", isScalar: false }
    }
});

metadataStore.addEntityType({
    shortName: "ParentValue",
    namespace: "Product",
    isComplexType: true,
    dataProperties: {
        id: { dataType: "String" },
        text: { dataType: "String" },
        previousValue: { complexTypeName: "ChildValue:#Product", isScalar: true }
    }
});

metadataStore.addEntityType({
    shortName: "ChildValue",
    namespace: "Product",
    isComplexType: true,
    dataProperties: {
        value: { dataType: "String" },
        text: { dataType: "String" }
    }
});

I previously had the issue where adding complexTypes to the array and calling cancelChanges was doubling the complexTypes in the list - I can requery the server for the items for now but it appears to be somewhat related

Calling rejectChanges on a entity with collection of complexTypes doubles the complexTypes in collection

1
I'll try to take a look at this tomorrow.Jay Traband
@JayTraband If you get a chance to look at this let me know - I can probably recreate in a jsBin or something if needed.PW Kad
Sorry, been buried... A re-creation would be great ;)Jay Traband

1 Answers

0
votes

I replicated the issue and fixed it. The issue happens when the entity is fetched a second time from the server, causing the updateTargetFromRay method to be called, which contains a bug.

Here is my fix:

// mathieug: clearing this array before updating it will cause 
// the _origValues to be set to length = 0. It must thus be done after the
// first item is pushed to the array(a beforeChange method is called in 
// the push function)
// oldVal.length = 0; // comment this line
var initialLength = oldVal.length; // keep initial count
if (Array.isArray(rawVal)) {
     rawVal.forEach(function (rawCo) {
         var newCo = dataType._createInstanceCore(target, dp);
         dataType._updateTargetFromRaw(newCo, rawCo, rawValueFn);
         dataType._initializeInstance(newCo);
         oldVal.push(newCo);
     });

     // Remove initial items
     oldVal.splice(0, initialLength);
 }