diff --git a/lib/query/lib/prepareForDelivery.js b/lib/query/lib/prepareForDelivery.js index eab1e21..2f5d1c6 100644 --- a/lib/query/lib/prepareForDelivery.js +++ b/lib/query/lib/prepareForDelivery.js @@ -180,11 +180,13 @@ function snapBackCaches(node) { // process stuff _.each(node.snapCaches, (linkName, cacheField) => { const isSingle = _.contains(node.snapCachesSingles, cacheField); + const linker = node.collection.getLinker(linkName); + // we do this because for one direct and one meta direct, id is not stored + const shoudStoreLinkStorage = !linker.isMany() && !linker.isVirtual(); + node.results.forEach(result => { if (result[cacheField]) { - const linker = node.collection.getLinker(linkName); - - if (!linker.isMany() && !linker.isVirtual()) { + if (shoudStoreLinkStorage) { Object.assign(result[cacheField], { _id: linker.isMeta() ? result[linker.linkStorageField]._id diff --git a/lib/query/testing/link-cache/server.test.js b/lib/query/testing/link-cache/server.test.js index 730b98e..af0ad9d 100644 --- a/lib/query/testing/link-cache/server.test.js +++ b/lib/query/testing/link-cache/server.test.js @@ -41,8 +41,6 @@ describe('Query Link Cache', function () { assert.isObject(post.author); assert.isString(post.author._id); - console.log(post.author); - unstubFind(Authors); // now that we specify an additional field, it should bypass the cache