在addToResultSelections时没有正确处理外键为空
This commit is contained in:
parent
a32eaf5856
commit
11ab7844ed
|
|
@ -1758,8 +1758,10 @@ var CascadeStore = /** @class */ (function (_super) {
|
||||||
* @param context
|
* @param context
|
||||||
*/
|
*/
|
||||||
CascadeStore.prototype.addToResultSelections = function (entity, rows, context) {
|
CascadeStore.prototype.addToResultSelections = function (entity, rows, context) {
|
||||||
|
var e_12, _a;
|
||||||
if (this.supportManyToOneJoin()) {
|
if (this.supportManyToOneJoin()) {
|
||||||
var attrsToPick_1 = [];
|
// 这里的外键连接有可能为空,需要使用所有的行的attr的并集来测试
|
||||||
|
var attrsToPick_2 = (0, lodash_1.uniq)(rows.map(function (ele) { return Object.keys(ele); }).flat());
|
||||||
var _loop_3 = function (attr) {
|
var _loop_3 = function (attr) {
|
||||||
var data = {};
|
var data = {};
|
||||||
var rel = this_3.judgeRelation(entity, attr);
|
var rel = this_3.judgeRelation(entity, attr);
|
||||||
|
|
@ -1773,14 +1775,24 @@ var CascadeStore = /** @class */ (function (_super) {
|
||||||
this_3.addToResultSelections(rel[0], rows.map(function (ele) { return ele[attr]; }).reduce(function (prev, current) { return prev.concat(current); }, []), context);
|
this_3.addToResultSelections(rel[0], rows.map(function (ele) { return ele[attr]; }).reduce(function (prev, current) { return prev.concat(current); }, []), context);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
attrsToPick_1.push(attr);
|
attrsToPick_2.push(attr);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var this_3 = this;
|
var this_3 = this;
|
||||||
for (var attr in rows[0]) {
|
try {
|
||||||
_loop_3(attr);
|
for (var attrsToPick_1 = tslib_1.__values(attrsToPick_2), attrsToPick_1_1 = attrsToPick_1.next(); !attrsToPick_1_1.done; attrsToPick_1_1 = attrsToPick_1.next()) {
|
||||||
|
var attr = attrsToPick_1_1.value;
|
||||||
|
_loop_3(attr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
var originRows = rows.map(function (ele) { return (0, lodash_1.pick)(ele, attrsToPick_1); });
|
catch (e_12_1) { e_12 = { error: e_12_1 }; }
|
||||||
|
finally {
|
||||||
|
try {
|
||||||
|
if (attrsToPick_1_1 && !attrsToPick_1_1.done && (_a = attrsToPick_1.return)) _a.call(attrsToPick_1);
|
||||||
|
}
|
||||||
|
finally { if (e_12) throw e_12.error; }
|
||||||
|
}
|
||||||
|
var originRows = rows.map(function (ele) { return (0, lodash_1.pick)(ele, attrsToPick_2); });
|
||||||
this.addSingleRowToResultSelections(entity, originRows, context);
|
this.addSingleRowToResultSelections(entity, originRows, context);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -1858,7 +1870,7 @@ var CascadeStore = /** @class */ (function (_super) {
|
||||||
if (!(cascadeSelectionFns.length > 0)) return [3 /*break*/, 3];
|
if (!(cascadeSelectionFns.length > 0)) return [3 /*break*/, 3];
|
||||||
ruException_2 = [];
|
ruException_2 = [];
|
||||||
return [4 /*yield*/, Promise.all(cascadeSelectionFns.map(function (ele) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
return [4 /*yield*/, Promise.all(cascadeSelectionFns.map(function (ele) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
||||||
var e_12, rows_2;
|
var e_13, rows_2;
|
||||||
return tslib_1.__generator(this, function (_a) {
|
return tslib_1.__generator(this, function (_a) {
|
||||||
switch (_a.label) {
|
switch (_a.label) {
|
||||||
case 0:
|
case 0:
|
||||||
|
|
@ -1868,13 +1880,13 @@ var CascadeStore = /** @class */ (function (_super) {
|
||||||
_a.sent();
|
_a.sent();
|
||||||
return [3 /*break*/, 3];
|
return [3 /*break*/, 3];
|
||||||
case 2:
|
case 2:
|
||||||
e_12 = _a.sent();
|
e_13 = _a.sent();
|
||||||
if (e_12 instanceof types_1.OakRowUnexistedException) {
|
if (e_13 instanceof types_1.OakRowUnexistedException) {
|
||||||
rows_2 = e_12.getRows();
|
rows_2 = e_13.getRows();
|
||||||
ruException_2.push.apply(ruException_2, tslib_1.__spreadArray([], tslib_1.__read(rows_2), false));
|
ruException_2.push.apply(ruException_2, tslib_1.__spreadArray([], tslib_1.__read(rows_2), false));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw e_12;
|
throw e_13;
|
||||||
}
|
}
|
||||||
return [3 /*break*/, 3];
|
return [3 /*break*/, 3];
|
||||||
case 3: return [2 /*return*/];
|
case 3: return [2 /*return*/];
|
||||||
|
|
|
||||||
|
|
@ -1794,8 +1794,11 @@ export abstract class CascadeStore<ED extends EntityDict & BaseEntityDict> exten
|
||||||
*/
|
*/
|
||||||
private addToResultSelections<T extends keyof ED, Cxt extends AsyncContext<ED>>(entity: T, rows: Partial<ED[T]['Schema']>[], context: Cxt) {
|
private addToResultSelections<T extends keyof ED, Cxt extends AsyncContext<ED>>(entity: T, rows: Partial<ED[T]['Schema']>[], context: Cxt) {
|
||||||
if (this.supportManyToOneJoin()) {
|
if (this.supportManyToOneJoin()) {
|
||||||
const attrsToPick: string[] = [];
|
// 这里的外键连接有可能为空,需要使用所有的行的attr的并集来测试
|
||||||
for (const attr in rows[0]) {
|
const attrsToPick: string[] = uniq(rows.map(
|
||||||
|
ele => Object.keys(ele)
|
||||||
|
).flat());
|
||||||
|
for (const attr of attrsToPick) {
|
||||||
const data: Partial<ED[T]['Schema']> = {}
|
const data: Partial<ED[T]['Schema']> = {}
|
||||||
const rel = this.judgeRelation(entity, attr);
|
const rel = this.judgeRelation(entity, attr);
|
||||||
if (rel === 2) {
|
if (rel === 2) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue