Skip to content

createInstance fails with Option cacheResponse: false #20

@rgant

Description

@rgant

Setting the option cacheResponse to false on a .find operation results in the error ""attrs" must be an object!" from js-data.

find call:

Users.find('me', {
    headers: {
        'Authorization': 'Basic ' + LoginService.isLogin()
    },
    cacheResponse: false
}).then(
    function success(usr){console.log(usr);}, 
    function fail(err){console.error(err);}
);

Tracing through the code it appears that the cacheResponse flag is checked here in js-data:

if (options.cacheResponse) {
    // injected created intem into the store
    var created = _this.inject(definition.name, attrs, options.orig());
    var id = created[definition.idAttribute];
    // mark item's `find` query as completed, so a subsequent `find` call for this item will resolve immediately
    var _resource = _this.store[resourceName];
    _resource.completedQueries[id] = new Date().getTime();
    _resource.saved[id] = DSUtils.updateTimestamp(_resource.saved[id]);
    return created;
} else {
    // just return an un-injected instance
    return _this.createInstance(resourceName, attrs, options);
}

If the code takes the 'true' path then there is no error, however if to tries to call createInstance directly then attrs is an [Object Array] instead of an [Object Object] and the call to DSUtils.isObject rejects it.

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions