pangea-server 1.0.28 → 1.0.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -19,6 +19,11 @@ class Db {
|
|
|
19
19
|
if (typeof filters === 'number') {
|
|
20
20
|
return scopedModel.findByPk(filters, { ...getIncludeAndWhere(model, include), ...baseOptions });
|
|
21
21
|
}
|
|
22
|
+
console.log({
|
|
23
|
+
...getIncludeAndWhere(model, include, filters),
|
|
24
|
+
order: getFinalOrder(order),
|
|
25
|
+
...baseOptions,
|
|
26
|
+
});
|
|
22
27
|
return scopedModel.findOne({
|
|
23
28
|
...getIncludeAndWhere(model, include, filters),
|
|
24
29
|
order: getFinalOrder(order),
|
|
@@ -203,11 +208,11 @@ function convertWhereKeys(obj) {
|
|
|
203
208
|
}
|
|
204
209
|
return obj;
|
|
205
210
|
}
|
|
206
|
-
function getIncludeAndWhere(model, includeItems, where, relDepth = new Map()
|
|
211
|
+
function getIncludeAndWhere(model, includeItems, where, relDepth = new Map()) {
|
|
207
212
|
const includeOptions = [];
|
|
208
213
|
const cleanWhere = { ...where };
|
|
209
214
|
for (const [relName, rel] of Object.entries(model.Relations)) {
|
|
210
|
-
const relKey = `${
|
|
215
|
+
const relKey = `${model.name}.${relName}`;
|
|
211
216
|
const currentDepth = relDepth.get(relKey) || 0;
|
|
212
217
|
const maxDepth = rel.joinDepth;
|
|
213
218
|
if (currentDepth >= maxDepth)
|
|
@@ -220,14 +225,12 @@ function getIncludeAndWhere(model, includeItems, where, relDepth = new Map(), pa
|
|
|
220
225
|
const newRelDepth = new Map(relDepth);
|
|
221
226
|
newRelDepth.set(relKey, currentDepth + 1);
|
|
222
227
|
const relModel = rel.getModelFn();
|
|
223
|
-
const nested = getIncludeAndWhere(relModel, nestedIncludeItems, relWhere, newRelDepth, relKey);
|
|
224
228
|
includeOptions.push({
|
|
225
229
|
model: relModel,
|
|
226
230
|
as: relName,
|
|
227
231
|
required: rel.required,
|
|
228
232
|
paranoid: rel.paranoid,
|
|
229
|
-
|
|
230
|
-
...(nested.where && { where: nested.where }),
|
|
233
|
+
...getIncludeAndWhere(relModel, nestedIncludeItems, relWhere, newRelDepth),
|
|
231
234
|
});
|
|
232
235
|
}
|
|
233
236
|
return {
|