diff --git a/lib/include.js b/lib/include.js index 5a0bb062..e044f062 100644 --- a/lib/include.js +++ b/lib/include.js @@ -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]; diff --git a/test/include.test.js b/test/include.test.js index bd918d5d..72980903 100644 --- a/test/include.test.js +++ b/test/include.test.js @@ -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);