MCPcopy Create free account
hub / github.com/CloudBoost/cloudboost / _include

Function _include

databases/mongo.js:47–184  ·  view source on GitHub ↗
(appId, include, docs)

Source from the content-addressed store, hash-verified

45 },
46
47 _include(appId, include, docs) {
48 // This function is for joins. :)
49 const _self = obj;
50 const join = [];
51 const deferred = q.defer();
52 try {
53 // include and merge all the documents.
54 const promises = [];
55 include.sort();
56 for (let i = 0; i < include.length; i++) {
57 const [columnName] = include[i].split('.');
58 join.push(columnName);
59 for (let k = 1; k < include.length; k++) {
60 if (columnName === include[k].split('.')[0]) {
61 i += 1;
62 } else {
63 break;
64 }
65 }
66 // include this column and merge.
67 const idList = [];
68 let collectionName = null;
69 _.each(docs, (doc) => {
70 if (doc[columnName] !== null) {
71 // checks if the doc[columnName] is an list of relations or a relation
72 if (Object.getPrototypeOf(doc[columnName]) === Object.prototype) {
73 if (doc[columnName] && doc[columnName]._id) {
74 if (doc[columnName]._type === 'file') {
75 collectionName = '_File';
76 } else {
77 collectionName = doc[columnName]._tableName;
78 }
79 idList.push(doc[columnName]._id);
80 }
81 } else {
82 for (let j = 0; j < doc[columnName].length; j++) {
83 if (doc[columnName][j] && doc[columnName][j]._id) {
84 if (doc[columnName][j]._type === 'file') {
85 collectionName = '_File';
86 } else {
87 collectionName = doc[columnName][j]._tableName;
88 }
89 idList.push(doc[columnName][j]._id);
90 }
91 }
92 }
93 }
94 }, null);
95
96 // if(idList.length >0 && collectionName) {
97 const qry = {};
98 qry._id = {};
99 qry._id.$in = idList;
100 promises.push(_self.document.fetch_data(appId, collectionName, qry));
101 // }
102 }
103
104 q.all(promises).then((arrayOfDocs) => {

Callers

nothing calls this directly

Calls 2

_deserializeFunction · 0.85
allMethod · 0.80

Tested by

no test coverage detected