cascadeStore中的bug
This commit is contained in:
parent
81ba6f3134
commit
ddd101e809
|
|
@ -680,9 +680,9 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
}
|
||||
_loop_2 = function (attr) {
|
||||
var relation, operationMto, actionMto, dataMto, filterMto, fkId, entity_1, result2, operationMto, actionMto, dataMto, filterMto, _d, _e, fkId, result2, _f, entityOtm_1, foreignKey_2, otmOperations, dealWithOneToMany, otmOperations_1, otmOperations_1_1, oper, e_2_1;
|
||||
var _g, _h, e_2, _j;
|
||||
return tslib_1.__generator(this, function (_k) {
|
||||
switch (_k.label) {
|
||||
var _g, _h, _j, e_2, _k;
|
||||
return tslib_1.__generator(this, function (_l) {
|
||||
switch (_l.label) {
|
||||
case 0:
|
||||
relation = (0, relation_1.judgeRelation)(this_2.storageSchema, entity, attr);
|
||||
if (!(relation === 1)) return [3 /*break*/, 1];
|
||||
|
|
@ -702,37 +702,50 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
}
|
||||
else if (action === 'create') {
|
||||
fkId = data.entityId, entity_1 = data.entity;
|
||||
(0, assert_1.default)(typeof fkId === 'string' || entity_1 === attr); // A中data的entityId作为B中filter的主键
|
||||
(0, assert_1.default)(filterMto.id && filterMto.id === fkId);
|
||||
/* Object.assign(operationMto, {
|
||||
filter: addFilterSegment({
|
||||
id: fkId,
|
||||
}), filterMto,
|
||||
}); */
|
||||
(0, assert_1.default)(typeof fkId === 'string' || entity_1 === attr);
|
||||
if (filterMto.id) {
|
||||
// 若已有id则不用处理,否则会干扰modi的后续判断(会根据filter来判断对象id,如果判断不出来去查实际的对象,但实际的对象其实还未创建好)
|
||||
(0, assert_1.default)(filterMto.id === fkId);
|
||||
}
|
||||
else {
|
||||
// A中data的entityId作为B中filter的主键
|
||||
Object.assign(operationMto, {
|
||||
filter: (0, filter_1.addFilterSegment)({
|
||||
id: fkId,
|
||||
}),
|
||||
filterMto: filterMto,
|
||||
});
|
||||
}
|
||||
}
|
||||
else {
|
||||
// 剩下三种情况都是B中的filter的id来自A中row的entityId
|
||||
(0, assert_1.default)(!data.hasOwnProperty('entityId') && !data.hasOwnProperty('entity')); // 这里不能再addFilterSegment,否则会造成后面判断不出来对应的id是多少。在实际情况中跑到这里应该不可能没有id
|
||||
(0, assert_1.default)(filterMto.id && typeof filterMto.id === 'string');
|
||||
/* Object.assign(operationMto, {
|
||||
filter: addFilterSegment({
|
||||
id: {
|
||||
$in: {
|
||||
entity,
|
||||
data: {
|
||||
entityId: 1,
|
||||
},
|
||||
filter: addFilterSegment({
|
||||
entity: attr,
|
||||
} as any, filter),
|
||||
}
|
||||
},
|
||||
}, filterMto),
|
||||
}); */
|
||||
(0, assert_1.default)(!data.hasOwnProperty('entityId') && !data.hasOwnProperty('entity'));
|
||||
if (filterMto.id) {
|
||||
// 若已有id则不用处理,否则会干扰modi的后续判断(会根据filter来判断对象id,如果判断不出来去查实际的对象,但实际的对象其实还未创建好)
|
||||
(0, assert_1.default)(typeof filterMto.id === 'string');
|
||||
}
|
||||
else {
|
||||
// A中data的entityId作为B中filter的主键
|
||||
Object.assign(operationMto, {
|
||||
filter: (0, filter_1.addFilterSegment)({
|
||||
id: {
|
||||
$in: {
|
||||
entity: entity,
|
||||
data: {
|
||||
entityId: 1,
|
||||
},
|
||||
filter: (0, filter_1.addFilterSegment)({
|
||||
entity: attr,
|
||||
}, filter),
|
||||
}
|
||||
},
|
||||
}, filterMto),
|
||||
});
|
||||
}
|
||||
}
|
||||
return [4 /*yield*/, this_2.cascadeUpdate(attr, operationMto, context, option2)];
|
||||
case 2:
|
||||
result2 = _k.sent();
|
||||
result2 = _l.sent();
|
||||
this_2.mergeOperationResult(result, result2);
|
||||
return [3 /*break*/, 16];
|
||||
case 3:
|
||||
|
|
@ -747,33 +760,45 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
else if (action === 'create') {
|
||||
_d = data, _e = "".concat(attr, "Id"), fkId = _d[_e];
|
||||
(0, assert_1.default)(typeof fkId === 'string');
|
||||
(0, assert_1.default)((filterMto === null || filterMto === void 0 ? void 0 : filterMto.id) && filterMto.id === fkId); // 这里不能再addFilterSegment,否则会造成后面判断不出来对应的id是多少。在实际情况中跑到这里应该不可能没有id
|
||||
/* Object.assign(operationMto, {
|
||||
filter: addFilterSegment(filterMto || {}, {
|
||||
id: fkId,
|
||||
}),
|
||||
}); */
|
||||
if (filterMto === null || filterMto === void 0 ? void 0 : filterMto.id) {
|
||||
// 若已有id则不用处理,否则会干扰modi的后续判断(会根据filter来判断对象id,如果判断不出来去查实际的对象,但实际的对象其实还未创建好)
|
||||
(0, assert_1.default)(filterMto.id === fkId);
|
||||
}
|
||||
else {
|
||||
// A中data的entityId作为B中filter的主键
|
||||
Object.assign(operationMto, {
|
||||
filter: (0, filter_1.addFilterSegment)(filterMto || {}, {
|
||||
id: fkId,
|
||||
}),
|
||||
});
|
||||
}
|
||||
}
|
||||
else {
|
||||
(0, assert_1.default)(!data.hasOwnProperty("".concat(attr, "Id")));
|
||||
(0, assert_1.default)((filterMto === null || filterMto === void 0 ? void 0 : filterMto.id) && typeof filterMto.id === 'string'); // 这里不能再addFilterSegment,否则会造成后面判断不出来对应的id是多少。在实际情况中跑到这里应该不可能没有id
|
||||
/* Object.assign(operationMto, {
|
||||
filter: addFilterSegment(filterMto || {}, {
|
||||
id: {
|
||||
$in: {
|
||||
entity,
|
||||
data: {
|
||||
[`${attr}Id`]: 1,
|
||||
},
|
||||
filter,
|
||||
}
|
||||
},
|
||||
}),
|
||||
}); */
|
||||
if (filterMto === null || filterMto === void 0 ? void 0 : filterMto.id) {
|
||||
// 若已有id则不用处理,否则会干扰modi的后续判断(会根据filter来判断对象id,如果判断不出来去查实际的对象,但实际的对象其实还未创建好)
|
||||
(0, assert_1.default)(typeof filterMto.id === 'string');
|
||||
}
|
||||
else {
|
||||
// A中data的entityId作为B中filter的主键
|
||||
Object.assign(operationMto, {
|
||||
filter: (0, filter_1.addFilterSegment)(filterMto || {}, {
|
||||
id: {
|
||||
$in: {
|
||||
entity: entity,
|
||||
data: (_j = {},
|
||||
_j["".concat(attr, "Id")] = 1,
|
||||
_j),
|
||||
filter: filter,
|
||||
}
|
||||
},
|
||||
}),
|
||||
});
|
||||
}
|
||||
}
|
||||
return [4 /*yield*/, this_2.cascadeUpdate(relation, operationMto, context, option2)];
|
||||
case 4:
|
||||
result2 = _k.sent();
|
||||
result2 = _l.sent();
|
||||
this_2.mergeOperationResult(result, result2);
|
||||
return [3 /*break*/, 16];
|
||||
case 5:
|
||||
|
|
@ -894,37 +919,37 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
});
|
||||
}); };
|
||||
if (!(otmOperations instanceof Array)) return [3 /*break*/, 14];
|
||||
_k.label = 6;
|
||||
_l.label = 6;
|
||||
case 6:
|
||||
_k.trys.push([6, 11, 12, 13]);
|
||||
_l.trys.push([6, 11, 12, 13]);
|
||||
otmOperations_1 = (e_2 = void 0, tslib_1.__values(otmOperations)), otmOperations_1_1 = otmOperations_1.next();
|
||||
_k.label = 7;
|
||||
_l.label = 7;
|
||||
case 7:
|
||||
if (!!otmOperations_1_1.done) return [3 /*break*/, 10];
|
||||
oper = otmOperations_1_1.value;
|
||||
return [4 /*yield*/, dealWithOneToMany(oper)];
|
||||
case 8:
|
||||
_k.sent();
|
||||
_k.label = 9;
|
||||
_l.sent();
|
||||
_l.label = 9;
|
||||
case 9:
|
||||
otmOperations_1_1 = otmOperations_1.next();
|
||||
return [3 /*break*/, 7];
|
||||
case 10: return [3 /*break*/, 13];
|
||||
case 11:
|
||||
e_2_1 = _k.sent();
|
||||
e_2_1 = _l.sent();
|
||||
e_2 = { error: e_2_1 };
|
||||
return [3 /*break*/, 13];
|
||||
case 12:
|
||||
try {
|
||||
if (otmOperations_1_1 && !otmOperations_1_1.done && (_j = otmOperations_1.return)) _j.call(otmOperations_1);
|
||||
if (otmOperations_1_1 && !otmOperations_1_1.done && (_k = otmOperations_1.return)) _k.call(otmOperations_1);
|
||||
}
|
||||
finally { if (e_2) throw e_2.error; }
|
||||
return [7 /*endfinally*/];
|
||||
case 13: return [3 /*break*/, 16];
|
||||
case 14: return [4 /*yield*/, dealWithOneToMany(otmOperations)];
|
||||
case 15:
|
||||
_k.sent();
|
||||
_k.label = 16;
|
||||
_l.sent();
|
||||
_l.label = 16;
|
||||
case 16: return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -695,33 +695,45 @@ export abstract class CascadeStore<ED extends EntityDict & BaseEntityDict, Cxt e
|
|||
}
|
||||
else if (action === 'create') {
|
||||
const { entityId: fkId, entity } = data;
|
||||
assert(typeof fkId === 'string' || entity === attr); // A中data的entityId作为B中filter的主键
|
||||
assert(filterMto.id && filterMto.id === fkId);
|
||||
/* Object.assign(operationMto, {
|
||||
filter: addFilterSegment({
|
||||
id: fkId,
|
||||
}), filterMto,
|
||||
}); */
|
||||
assert(typeof fkId === 'string' || entity === attr);
|
||||
if (filterMto.id) {
|
||||
// 若已有id则不用处理,否则会干扰modi的后续判断(会根据filter来判断对象id,如果判断不出来去查实际的对象,但实际的对象其实还未创建好)
|
||||
assert(filterMto.id === fkId);
|
||||
}
|
||||
else {
|
||||
// A中data的entityId作为B中filter的主键
|
||||
Object.assign(operationMto, {
|
||||
filter: addFilterSegment({
|
||||
id: fkId,
|
||||
}), filterMto,
|
||||
});
|
||||
}
|
||||
}
|
||||
else {
|
||||
// 剩下三种情况都是B中的filter的id来自A中row的entityId
|
||||
assert(!data.hasOwnProperty('entityId') && !data.hasOwnProperty('entity')); // 这里不能再addFilterSegment,否则会造成后面判断不出来对应的id是多少。在实际情况中跑到这里应该不可能没有id
|
||||
assert(filterMto.id && typeof filterMto.id === 'string');
|
||||
/* Object.assign(operationMto, {
|
||||
filter: addFilterSegment({
|
||||
id: {
|
||||
$in: {
|
||||
entity,
|
||||
data: {
|
||||
entityId: 1,
|
||||
},
|
||||
filter: addFilterSegment({
|
||||
entity: attr,
|
||||
} as any, filter),
|
||||
}
|
||||
},
|
||||
}, filterMto),
|
||||
}); */
|
||||
assert(!data.hasOwnProperty('entityId') && !data.hasOwnProperty('entity'));
|
||||
if (filterMto.id) {
|
||||
// 若已有id则不用处理,否则会干扰modi的后续判断(会根据filter来判断对象id,如果判断不出来去查实际的对象,但实际的对象其实还未创建好)
|
||||
assert(typeof filterMto.id === 'string');
|
||||
}
|
||||
else {
|
||||
// A中data的entityId作为B中filter的主键
|
||||
Object.assign(operationMto, {
|
||||
filter: addFilterSegment({
|
||||
id: {
|
||||
$in: {
|
||||
entity,
|
||||
data: {
|
||||
entityId: 1,
|
||||
},
|
||||
filter: addFilterSegment({
|
||||
entity: attr,
|
||||
} as any, filter),
|
||||
}
|
||||
},
|
||||
}, filterMto),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const result2 = await this.cascadeUpdate(attr, operationMto, context, option2);
|
||||
|
|
@ -740,29 +752,41 @@ export abstract class CascadeStore<ED extends EntityDict & BaseEntityDict, Cxt e
|
|||
else if (action === 'create') {
|
||||
const { [`${attr}Id`]: fkId } = data;
|
||||
assert(typeof fkId === 'string');
|
||||
assert(filterMto?.id && filterMto.id === fkId); // 这里不能再addFilterSegment,否则会造成后面判断不出来对应的id是多少。在实际情况中跑到这里应该不可能没有id
|
||||
/* Object.assign(operationMto, {
|
||||
filter: addFilterSegment(filterMto || {}, {
|
||||
id: fkId,
|
||||
}),
|
||||
}); */
|
||||
if (filterMto?.id) {
|
||||
// 若已有id则不用处理,否则会干扰modi的后续判断(会根据filter来判断对象id,如果判断不出来去查实际的对象,但实际的对象其实还未创建好)
|
||||
assert(filterMto.id === fkId)
|
||||
}
|
||||
else {
|
||||
// A中data的entityId作为B中filter的主键
|
||||
Object.assign(operationMto, {
|
||||
filter: addFilterSegment(filterMto || {}, {
|
||||
id: fkId,
|
||||
}),
|
||||
});
|
||||
}
|
||||
}
|
||||
else {
|
||||
assert(!data.hasOwnProperty(`${attr}Id`));
|
||||
assert(filterMto?.id && typeof filterMto.id === 'string'); // 这里不能再addFilterSegment,否则会造成后面判断不出来对应的id是多少。在实际情况中跑到这里应该不可能没有id
|
||||
/* Object.assign(operationMto, {
|
||||
filter: addFilterSegment(filterMto || {}, {
|
||||
id: {
|
||||
$in: {
|
||||
entity,
|
||||
data: {
|
||||
[`${attr}Id`]: 1,
|
||||
},
|
||||
filter,
|
||||
}
|
||||
},
|
||||
}),
|
||||
}); */
|
||||
if (filterMto?.id) {
|
||||
// 若已有id则不用处理,否则会干扰modi的后续判断(会根据filter来判断对象id,如果判断不出来去查实际的对象,但实际的对象其实还未创建好)
|
||||
assert(typeof filterMto.id === 'string');
|
||||
}
|
||||
else {
|
||||
// A中data的entityId作为B中filter的主键
|
||||
Object.assign(operationMto, {
|
||||
filter: addFilterSegment(filterMto || {}, {
|
||||
id: {
|
||||
$in: {
|
||||
entity,
|
||||
data: {
|
||||
[`${attr}Id`]: 1,
|
||||
},
|
||||
filter,
|
||||
}
|
||||
},
|
||||
}),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const result2 = await this.cascadeUpdate(relation, operationMto, context, option2);
|
||||
|
|
|
|||
Loading…
Reference in New Issue