pangea-server 3.3.116 → 3.3.118
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.
- package/dist/database/db.class.js +20 -14
- package/package.json +1 -1
|
@@ -304,31 +304,37 @@ function getFinalOrder(order, config = {}) {
|
|
|
304
304
|
});
|
|
305
305
|
return [...finalOrder, ...(!config.attributes ? [['createdAt', 'DESC']] : [])];
|
|
306
306
|
}
|
|
307
|
-
function
|
|
307
|
+
function processRelInstance(model, jsonInstance) {
|
|
308
308
|
for (const [relName] of Object.entries(model.Relations)) {
|
|
309
|
-
|
|
310
|
-
const relInstance = instance[relName];
|
|
311
|
-
console.log('relInstance');
|
|
309
|
+
const relInstance = jsonInstance[relName];
|
|
312
310
|
if (!relInstance)
|
|
313
311
|
continue;
|
|
314
312
|
const relModel = model.Relations[relName].getModelFn();
|
|
315
313
|
if (Array.isArray(relInstance)) {
|
|
316
|
-
|
|
317
|
-
relInstance.forEach((i) => processInstance(relModel, i));
|
|
314
|
+
jsonInstance[relName] = relInstance.map((relIns) => processRelInstance(relModel, relIns));
|
|
318
315
|
}
|
|
319
316
|
else {
|
|
320
|
-
|
|
321
|
-
console.dir(relInstance.toJSON(), { depth: 1 });
|
|
322
|
-
processInstance(relModel, relInstance);
|
|
317
|
+
jsonInstance[relName] = processRelInstance(relModel, relInstance);
|
|
323
318
|
}
|
|
324
319
|
}
|
|
325
|
-
|
|
320
|
+
model.InitInstance(jsonInstance);
|
|
321
|
+
return jsonInstance;
|
|
322
|
+
}
|
|
323
|
+
function processInstance(model, instance) {
|
|
326
324
|
const jsonInstance = instance.toJSON();
|
|
327
|
-
|
|
328
|
-
|
|
325
|
+
for (const [relName] of Object.entries(model.Relations)) {
|
|
326
|
+
const relInstance = jsonInstance[relName];
|
|
327
|
+
if (!relInstance)
|
|
328
|
+
continue;
|
|
329
|
+
const relModel = model.Relations[relName].getModelFn();
|
|
330
|
+
if (Array.isArray(relInstance)) {
|
|
331
|
+
jsonInstance[relName] = relInstance.map((relIns) => processRelInstance(relModel, relIns));
|
|
332
|
+
}
|
|
333
|
+
else {
|
|
334
|
+
jsonInstance[relName] = processRelInstance(relModel, relInstance);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
329
337
|
model.InitInstance(jsonInstance);
|
|
330
|
-
console.log('model.InitInstance()');
|
|
331
|
-
console.dir(jsonInstance, { depth: 1 });
|
|
332
338
|
return jsonInstance;
|
|
333
339
|
}
|
|
334
340
|
function processInstances(model, instances) {
|