在cascadeSelection解构时保留原来的projection
This commit is contained in:
parent
704d5c432a
commit
01f236e62a
|
|
@ -325,25 +325,16 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
};
|
||||
CascadeStore.prototype.destructCascadeSelect = function (entity, projection2, context, cascadeSelectFn, aggregateFn, option) {
|
||||
var _this = this;
|
||||
var projection = {};
|
||||
var cascadeSelectionFns = [];
|
||||
var supportMtoJoin = this.supportManyToOneJoin();
|
||||
var toModi = this.getSchema()[entity].toModi;
|
||||
(0, assert_1.default)(typeof projection2 === 'object');
|
||||
var _loop_1 = function (attr) {
|
||||
var _a, _b, _c, _d;
|
||||
var relation = (0, relation_1.judgeRelation)(this_1.storageSchema, entity, attr);
|
||||
if (relation === 1 || relation == 0) {
|
||||
Object.assign(projection, (_a = {},
|
||||
_a[attr] = projection2[attr],
|
||||
_a));
|
||||
}
|
||||
else if (relation === 2) {
|
||||
// 基于entity/entityId的多对一
|
||||
Object.assign(projection, {
|
||||
entity: 1,
|
||||
entityId: 1,
|
||||
});
|
||||
(0, assert_1.default)(typeof projection2[attr] === 'object');
|
||||
if (supportMtoJoin) {
|
||||
cascadeSelectionFns.push(function (result) {
|
||||
|
|
@ -366,10 +357,7 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
});
|
||||
}
|
||||
});
|
||||
var _e = this_1.destructCascadeSelect(attr, projection2[attr], context, cascadeSelectFn, aggregateFn, option), subProjection = _e.projection, subCascadeSelectionFns = _e.cascadeSelectionFns;
|
||||
Object.assign(projection, (_b = {},
|
||||
_b[attr] = subProjection,
|
||||
_b));
|
||||
var _a = this_1.destructCascadeSelect(attr, projection2[attr], context, cascadeSelectFn, aggregateFn, option), subProjection = _a.projection, subCascadeSelectionFns = _a.cascadeSelectionFns;
|
||||
subCascadeSelectionFns.forEach(function (ele) { return cascadeSelectionFns.push(function (result) {
|
||||
return ele(result.map(function (ele2) { return ele2[attr]; }).filter(function (ele2) { return !!ele2; }));
|
||||
}); });
|
||||
|
|
@ -435,9 +423,6 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
}
|
||||
}
|
||||
else if (typeof relation === 'string') {
|
||||
Object.assign(projection, (_c = {},
|
||||
_c["".concat(attr, "Id")] = 1,
|
||||
_c));
|
||||
(0, assert_1.default)(typeof projection2[attr] === 'object');
|
||||
if (supportMtoJoin) {
|
||||
if (!toModi) {
|
||||
|
|
@ -460,10 +445,7 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
}
|
||||
});
|
||||
}
|
||||
var _f = this_1.destructCascadeSelect(relation, projection2[attr], context, cascadeSelectFn, aggregateFn, option), subProjection = _f.projection, subCascadeSelectionFns = _f.cascadeSelectionFns;
|
||||
Object.assign(projection, (_d = {},
|
||||
_d[attr] = subProjection,
|
||||
_d));
|
||||
var _b = this_1.destructCascadeSelect(relation, projection2[attr], context, cascadeSelectFn, aggregateFn, option), subProjection = _b.projection, subCascadeSelectionFns = _b.cascadeSelectionFns;
|
||||
subCascadeSelectionFns.forEach(function (ele) { return cascadeSelectionFns.push(function (result) {
|
||||
return ele(result.map(function (ele2) { return ele2[attr]; }).filter(function (ele2) { return !!ele2; }));
|
||||
}); });
|
||||
|
|
@ -529,8 +511,8 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
}
|
||||
else {
|
||||
(0, assert_1.default)(relation instanceof Array);
|
||||
var _g = projection2[attr], subProjection_1 = _g.data, subFilter_1 = _g.filter, indexFrom_1 = _g.indexFrom, count_1 = _g.count, subSorter_1 = _g.sorter;
|
||||
var _h = tslib_1.__read(relation, 2), entity2_1 = _h[0], foreignKey_1 = _h[1];
|
||||
var _c = projection2[attr], subProjection_1 = _c.data, subFilter_1 = _c.filter, indexFrom_1 = _c.indexFrom, count_1 = _c.count, subSorter_1 = _c.sorter;
|
||||
var _d = tslib_1.__read(relation, 2), entity2_1 = _d[0], foreignKey_1 = _d[1];
|
||||
var isAggr = attr.endsWith('$$aggr');
|
||||
if (foreignKey_1) {
|
||||
// 基于属性的一对多
|
||||
|
|
@ -700,7 +682,7 @@ var CascadeStore = /** @class */ (function (_super) {
|
|||
_loop_1(attr);
|
||||
}
|
||||
return {
|
||||
projection: projection,
|
||||
projection: projection2,
|
||||
cascadeSelectionFns: cascadeSelectionFns,
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -548,7 +548,6 @@ function createCreateCheckers(schema) {
|
|||
var illegalNullAttrs = (0, lodash_1.difference)(notNullAttrs, Object.keys(data2));
|
||||
if (illegalNullAttrs.length > 0) {
|
||||
var emtpyAttrs = [];
|
||||
'';
|
||||
try {
|
||||
// 要处理多对一的cascade create
|
||||
for (var illegalNullAttrs_1 = (e_5 = void 0, tslib_1.__values(illegalNullAttrs)), illegalNullAttrs_1_1 = illegalNullAttrs_1.next(); !illegalNullAttrs_1_1.done; illegalNullAttrs_1_1 = illegalNullAttrs_1.next()) {
|
||||
|
|
|
|||
|
|
@ -379,7 +379,6 @@ export abstract class CascadeStore<ED extends EntityDict & BaseEntityDict> exten
|
|||
cascadeSelectFn: <T2 extends keyof ED>(entity2: T2, selection: ED[T2]['Selection'], context: Cxt, op: OP) => Partial<ED[T2]['Schema']>[] | Promise<Partial<ED[T2]['Schema']>[]>,
|
||||
aggregateFn: <T2 extends keyof ED>(entity2: T2, aggregation: ED[T2]['Aggregation'], context: Cxt, op: OP) => AggregationResult<ED[T2]['Schema']> | Promise<AggregationResult<ED[T2]['Schema']>>,
|
||||
option: OP) {
|
||||
const projection: ED[T]['Selection']['data'] = {};
|
||||
const cascadeSelectionFns: Array<(result: Partial<ED[T]['Schema']>[]) => Promise<void> | void> = [];
|
||||
|
||||
const supportMtoJoin = this.supportManyToOneJoin();
|
||||
|
|
@ -389,17 +388,9 @@ export abstract class CascadeStore<ED extends EntityDict & BaseEntityDict> exten
|
|||
for (const attr in projection2) {
|
||||
const relation = judgeRelation(this.storageSchema, entity, attr);
|
||||
if (relation === 1 || relation == 0) {
|
||||
Object.assign(projection, {
|
||||
[attr]: projection2[attr],
|
||||
});
|
||||
}
|
||||
else if (relation === 2) {
|
||||
// 基于entity/entityId的多对一
|
||||
Object.assign(projection, {
|
||||
entity: 1,
|
||||
entityId: 1,
|
||||
});
|
||||
|
||||
assert(typeof projection2[attr] === 'object');
|
||||
if (supportMtoJoin) {
|
||||
cascadeSelectionFns.push(
|
||||
|
|
@ -430,9 +421,6 @@ export abstract class CascadeStore<ED extends EntityDict & BaseEntityDict> exten
|
|||
projection: subProjection,
|
||||
cascadeSelectionFns: subCascadeSelectionFns,
|
||||
} = this.destructCascadeSelect(attr, projection2[attr], context, cascadeSelectFn, aggregateFn, option);
|
||||
Object.assign(projection, {
|
||||
[attr]: subProjection,
|
||||
});
|
||||
subCascadeSelectionFns.forEach(
|
||||
ele => cascadeSelectionFns.push(
|
||||
(result) => {
|
||||
|
|
@ -516,9 +504,6 @@ export abstract class CascadeStore<ED extends EntityDict & BaseEntityDict> exten
|
|||
}
|
||||
}
|
||||
else if (typeof relation === 'string') {
|
||||
Object.assign(projection, {
|
||||
[`${attr}Id`]: 1,
|
||||
});
|
||||
assert(typeof projection2[attr] === 'object');
|
||||
if (supportMtoJoin) {
|
||||
if (!toModi) {
|
||||
|
|
@ -549,9 +534,6 @@ export abstract class CascadeStore<ED extends EntityDict & BaseEntityDict> exten
|
|||
projection: subProjection,
|
||||
cascadeSelectionFns: subCascadeSelectionFns,
|
||||
} = this.destructCascadeSelect(relation, projection2[attr], context, cascadeSelectFn, aggregateFn, option);
|
||||
Object.assign(projection, {
|
||||
[attr]: subProjection,
|
||||
});
|
||||
subCascadeSelectionFns.forEach(
|
||||
ele => cascadeSelectionFns.push(
|
||||
(result) => {
|
||||
|
|
@ -829,7 +811,7 @@ export abstract class CascadeStore<ED extends EntityDict & BaseEntityDict> exten
|
|||
}
|
||||
|
||||
return {
|
||||
projection,
|
||||
projection: projection2,
|
||||
cascadeSelectionFns,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue