jaydata icon indicating copy to clipboard operation
jaydata copied to clipboard

Cannot refresh entity with multiple key properties

Open phil-mitchell opened this issue 9 years ago • 0 comments

If an entity has multiple key properties it cannot be refresh()ed. An error is reported:

Property not found!: Parameter 'key_param_2' not found in context.

This boils down to this function:

_getKeyObjectFromEntity: function (obj, entityType) {
    var key;
    var keyDefs = entityType.memberDefinitions.getKeyProperties();
    if (keyDefs.length === 1)
        key = obj && typeof obj === 'object' ? obj[keyDefs[0].name] : obj;
    else {
        key = {};
        for (var i = 0; i < keyDefs.length; i++) {
            key[keyDefs[0].name] = obj ? obj[keyDefs[0].name] : obj;
        }
    }
    return key;
},

Note that you just write keyDefs[0] multiple times, rather than using "i" for its intended purpose. Fixing this resolves the problem.

phil-mitchell avatar May 14 '15 02:05 phil-mitchell