Skip to content

Commit 291a470

Browse files
committed
storeOneResults fix
1 parent 386e3bf commit 291a470

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

lib/query/lib/prepareForDelivery.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,21 @@ export function storeOneResults(node, sameLevelResults) {
177177
return;
178178
}
179179

180-
storeOneResults(collectionNode, dot.pick(collectionNode.linkName, result));
180+
const [root, ...rest] = collectionNode.linkName.split('.');
181+
if (rest.length === 0) {
182+
storeOneResults(collectionNode, result[root]);
183+
}
184+
else {
185+
const rootValue = result[root];
186+
if (_.isArray(rootValue)) {
187+
rootValue.forEach(value => {
188+
storeOneResults(collectionNode, dot.pick(rest.join('.'), value));
189+
});
190+
}
191+
else if (_.isObject(rootValue)) {
192+
storeOneResults(collectionNode, dot.pick(rest.join('.'), rootValue));
193+
}
194+
}
181195
});
182196

183197
if (collectionNode.isOneResult) {

0 commit comments

Comments
 (0)