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