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);
|
||||
// Set to null if the owner doesn't exist
|
||||
obj.__cachedRelations[relationName] = null;
|
||||
obj[relationName] = null;
|
||||
if(obj === inst) {
|
||||
obj.__data[relationName] = null;
|
||||
} else {
|
||||
obj[relationName] = null;
|
||||
}
|
||||
return callback();
|
||||
}
|
||||
}
|
||||
|
@ -123,7 +127,12 @@ Inclusion.include = function (objects, include, cb) {
|
|||
} else {
|
||||
defineCachedRelations(obj);
|
||||
obj.__cachedRelations[relationName] = result;
|
||||
obj[relationName] = result;
|
||||
if(obj === inst) {
|
||||
obj.__data[relationName] = result;
|
||||
obj.strict = false;
|
||||
} else {
|
||||
obj[relationName] = result;
|
||||
}
|
||||
|
||||
if (subInclude && result) {
|
||||
var subItems = relation.multiple ? result : [result];
|
||||
|
|
|
@ -70,6 +70,7 @@ describe('include', function () {
|
|||
should.exist(user);
|
||||
user.id.should.equal(p.ownerId);
|
||||
user.__cachedRelations.should.have.property('posts');
|
||||
user.should.have.property('posts');
|
||||
user.__cachedRelations.posts.forEach(function (pp) {
|
||||
pp.userId.should.equal(user.id);
|
||||
});
|
||||
|
@ -97,6 +98,7 @@ describe('include', function () {
|
|||
user.__cachedRelations.should.have.property('posts');
|
||||
user.__cachedRelations.posts.forEach(function (pp) {
|
||||
pp.userId.should.equal(user.id);
|
||||
pp.should.have.property('author');
|
||||
pp.__cachedRelations.should.have.property('author');
|
||||
var author = pp.__cachedRelations.author;
|
||||
author.id.should.equal(user.id);
|
||||
|
|
Loading…
Reference in New Issue