Skip to content

Commit

Permalink
Fixes #239
Browse files Browse the repository at this point in the history
  • Loading branch information
jmdobry committed Nov 3, 2015
1 parent dbf2022 commit 3f962e3
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 23 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,9 @@
##### 2.8.1 - 02 November 2015

###### Backwards compatible bug fixes
- #239 - loadRelations assumes cacheResponse and linkRelations options are true
- #259, #260 - Reverting undefined keys by @davincho

##### 2.8.0 - 26 October 2015

###### Backwards compatible API changes
Expand Down
23 changes: 14 additions & 9 deletions dist/js-data-debug.js
@@ -1,6 +1,6 @@
/*!
* js-data
* @version 2.8.0 - Homepage <http://www.js-data.io/>
* @version 2.8.1 - Homepage <http://www.js-data.io/>
* @author Jason Dobry <jason.dobry@gmail.com>
* @copyright (c) 2014-2015 Jason Dobry
* @license MIT <https://github.com/js-data/js-data/blob/master/LICENSE>
Expand Down Expand Up @@ -84,10 +84,10 @@ return /******/ (function(modules) { // webpackBootstrap
return new _datastoreIndex['default'](options);
},
version: {
full: '2.8.0',
full: '2.8.1',
major: parseInt('2', 10),
minor: parseInt('8', 10),
patch: parseInt('0', 10),
patch: parseInt('1', 10),
alpha: true ? 'false' : false,
beta: true ? 'false' : false
}
Expand Down Expand Up @@ -3360,14 +3360,14 @@ return /******/ (function(modules) { // webpackBootstrap
var _options = _check$call9._options;

var preserve = _options.preserve || [];
var injectObj = {};

if (preserve.length === 0) {
return definition.inject(_this.previous(_resourceName, _id));
injectObj = _this.previous(_resourceName, _id);
} else {
var _ret2 = (function () {
var instance = definition.get(id);
var previousInstance = _this.previous(_resourceName, _id);
var injectObj = {};

if (!instance) {
return {
Expand All @@ -3382,14 +3382,14 @@ return /******/ (function(modules) { // webpackBootstrap
injectObj[key] = previousInstance[key];
}
});

return {
v: definition.inject(injectObj)
};
})();

if (typeof _ret2 === 'object') return _ret2.v;
}

return definition.inject(injectObj, {
onConflict: 'replace'
});
}
};

Expand Down Expand Up @@ -5043,6 +5043,11 @@ return /******/ (function(modules) { // webpackBootstrap
}

if (task) {
if (!_options.linkRelations) {
task = task.then(function (data) {
instance[def.localField] = data;
});
}
tasks.push(task);
}
}
Expand Down
23 changes: 14 additions & 9 deletions dist/js-data.js
@@ -1,6 +1,6 @@
/*!
* js-data
* @version 2.8.0 - Homepage <http://www.js-data.io/>
* @version 2.8.1 - Homepage <http://www.js-data.io/>
* @author Jason Dobry <jason.dobry@gmail.com>
* @copyright (c) 2014-2015 Jason Dobry
* @license MIT <https://github.com/js-data/js-data/blob/master/LICENSE>
Expand Down Expand Up @@ -84,10 +84,10 @@ return /******/ (function(modules) { // webpackBootstrap
return new _datastoreIndex['default'](options);
},
version: {
full: '2.8.0',
full: '2.8.1',
major: parseInt('2', 10),
minor: parseInt('8', 10),
patch: parseInt('0', 10),
patch: parseInt('1', 10),
alpha: true ? 'false' : false,
beta: true ? 'false' : false
}
Expand Down Expand Up @@ -3350,14 +3350,14 @@ return /******/ (function(modules) { // webpackBootstrap
var _options = _check$call9._options;

var preserve = _options.preserve || [];
var injectObj = {};

if (preserve.length === 0) {
return definition.inject(_this.previous(_resourceName, _id));
injectObj = _this.previous(_resourceName, _id);
} else {
var _ret2 = (function () {
var instance = definition.get(id);
var previousInstance = _this.previous(_resourceName, _id);
var injectObj = {};

if (!instance) {
return {
Expand All @@ -3372,14 +3372,14 @@ return /******/ (function(modules) { // webpackBootstrap
injectObj[key] = previousInstance[key];
}
});

return {
v: definition.inject(injectObj)
};
})();

if (typeof _ret2 === 'object') return _ret2.v;
}

return definition.inject(injectObj, {
onConflict: 'replace'
});
}
};

Expand Down Expand Up @@ -5019,6 +5019,11 @@ return /******/ (function(modules) { // webpackBootstrap
}

if (task) {
if (!_options.linkRelations) {
task = task.then(function (data) {
instance[def.localField] = data;
});
}
tasks.push(task);
}
}
Expand Down
4 changes: 2 additions & 2 deletions dist/js-data.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/js-data.min.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "js-data",
"description": "Robust, framework-agnostic in-memory data store.",
"version": "2.8.0",
"version": "2.8.1",
"homepage": "http://www.js-data.io",
"repository": {
"type": "git",
Expand Down
5 changes: 5 additions & 0 deletions src/datastore/async_methods/loadRelations.js
Expand Up @@ -93,6 +93,11 @@ module.exports = function loadRelations (resourceName, instance, relations, opti
}

if (task) {
if (!_options.linkRelations) {
task = task.then(function (data) {
instance[def.localField] = data
})
}
tasks.push(task)
}
}
Expand Down
50 changes: 49 additions & 1 deletion test/browser/datastore/async_methods/loadRelations.test.js
Expand Up @@ -492,7 +492,7 @@ describe('DS#loadRelations', function () {
}
}
})

var foo = Foo.inject({ id: 1 });

return foo.DSLoadRelations(['bar']).then(function (foo) {
Expand Down Expand Up @@ -622,4 +622,52 @@ describe('DS#loadRelations', function () {
});
});
});
it('should still work when linkRelations is false', function () {
var _this = this;
var store = new JSData.DS({
linkRelations: false
});
store.registerAdapter('http', dsHttpAdapter, { default: true });
var Foo = store.defineResource({
name: 'foo',
relations: {
hasMany: {
bar: {
localField: 'bars',
foreignKey: 'fooId'
}
},
belongsTo: {
beep: {
localField: 'beep',
localKey: 'beepId'
}
}
}
})
var Bar = store.defineResource('bar')
var Beep = store.defineResource('beep')

var foo = Foo.inject({
id: 1,
beepId: 2
})

setTimeout(function () {
assert.equal(2, _this.requests.length);
assert.equal(_this.requests[0].url, 'bar?fooId=1');
assert.equal(_this.requests[0].method, 'GET');
assert.equal(_this.requests[1].url, 'beep/2');
assert.equal(_this.requests[1].method, 'GET');
_this.requests[0].respond(200, { 'Content-Type': 'application/json' }, DSUtils.toJson([{ id: 3, fooId: 1 }]));
_this.requests[1].respond(200, { 'Content-Type': 'application/json' }, DSUtils.toJson({ id: 2 }));
}, 60);

return foo.DSLoadRelations(['bar', 'beep']).then(function (foo) {
assert.objectsEqual(foo.bars, [{ id: 3, fooId: 1 }]);
assert.objectsEqual(foo.beep, { id: 2 });
assert.isTrue(foo.bars === foo.bars);
assert.isTrue(foo.beep === foo.beep);
});
});
});

0 comments on commit 3f962e3

Please sign in to comment.