Set the relation property correctly
See https://github.com/strongloop/loopback/issues/218
This commit is contained in:
parent
82c687737a
commit
0e7acec591
|
@ -110,7 +110,11 @@ Inclusion.include = function (objects, include, cb) {
|
||||||
defineCachedRelations(obj);
|
defineCachedRelations(obj);
|
||||||
// Set to null if the owner doesn't exist
|
// Set to null if the owner doesn't exist
|
||||||
obj.__cachedRelations[relationName] = null;
|
obj.__cachedRelations[relationName] = null;
|
||||||
|
if(obj === inst) {
|
||||||
|
obj.__data[relationName] = null;
|
||||||
|
} else {
|
||||||
obj[relationName] = null;
|
obj[relationName] = null;
|
||||||
|
}
|
||||||
return callback();
|
return callback();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -123,7 +127,12 @@ Inclusion.include = function (objects, include, cb) {
|
||||||
} else {
|
} else {
|
||||||
defineCachedRelations(obj);
|
defineCachedRelations(obj);
|
||||||
obj.__cachedRelations[relationName] = result;
|
obj.__cachedRelations[relationName] = result;
|
||||||
|
if(obj === inst) {
|
||||||
|
obj.__data[relationName] = result;
|
||||||
|
obj.strict = false;
|
||||||
|
} else {
|
||||||
obj[relationName] = result;
|
obj[relationName] = result;
|
||||||
|
}
|
||||||
|
|
||||||
if (subInclude && result) {
|
if (subInclude && result) {
|
||||||
var subItems = relation.multiple ? result : [result];
|
var subItems = relation.multiple ? result : [result];
|
||||||
|
|
|
@ -70,6 +70,7 @@ describe('include', function () {
|
||||||
should.exist(user);
|
should.exist(user);
|
||||||
user.id.should.equal(p.ownerId);
|
user.id.should.equal(p.ownerId);
|
||||||
user.__cachedRelations.should.have.property('posts');
|
user.__cachedRelations.should.have.property('posts');
|
||||||
|
user.should.have.property('posts');
|
||||||
user.__cachedRelations.posts.forEach(function (pp) {
|
user.__cachedRelations.posts.forEach(function (pp) {
|
||||||
pp.userId.should.equal(user.id);
|
pp.userId.should.equal(user.id);
|
||||||
});
|
});
|
||||||
|
@ -97,6 +98,7 @@ describe('include', function () {
|
||||||
user.__cachedRelations.should.have.property('posts');
|
user.__cachedRelations.should.have.property('posts');
|
||||||
user.__cachedRelations.posts.forEach(function (pp) {
|
user.__cachedRelations.posts.forEach(function (pp) {
|
||||||
pp.userId.should.equal(user.id);
|
pp.userId.should.equal(user.id);
|
||||||
|
pp.should.have.property('author');
|
||||||
pp.__cachedRelations.should.have.property('author');
|
pp.__cachedRelations.should.have.property('author');
|
||||||
var author = pp.__cachedRelations.author;
|
var author = pp.__cachedRelations.author;
|
||||||
author.id.should.equal(user.id);
|
author.id.should.equal(user.id);
|
||||||
|
|
Loading…
Reference in New Issue