@ruiapp/rapid-core 0.7.4 → 0.7.6

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/index.js CHANGED
@@ -2815,18 +2815,30 @@ async function findEntities(server, dataAccessor, options) {
2815
2815
  continue;
2816
2816
  }
2817
2817
  if (isManyRelation) {
2818
- const relationLinks = await findManyRelationLinksViaLinkTable({
2818
+ const selectRelationOptions = relationOptions[relationProperty.code];
2819
+ const { relationLinks, targetEntities } = await findManyRelationLinksViaLinkTable({
2819
2820
  server,
2820
2821
  routeContext,
2821
2822
  mainModel: relationModel,
2822
2823
  relationProperty,
2823
2824
  mainEntityIds: entityIds,
2824
- selectRelationOptions: relationOptions[relationProperty.code],
2825
+ selectRelationOptions,
2825
2826
  });
2827
+ // 如果查询关联实体时指定了orderBy,则按照targetEntities的顺序,否则按照relationLinks的顺序。
2828
+ const selectRelationOrderByOptionsSpecified = selectRelationOptions && lodash.isObject(selectRelationOptions) && selectRelationOptions.orderBy;
2826
2829
  lodash.forEach(rows, (row) => {
2827
- row[relationProperty.code] = lodash.filter(relationLinks, (link) => {
2828
- return link[relationProperty.selfIdColumnName] == row["id"];
2829
- }).map((link) => mapDbRowToEntity(server, relationModel, link.targetEntity, options.keepNonPropertyFields));
2830
+ if (selectRelationOrderByOptionsSpecified) {
2831
+ row[relationProperty.code] = lodash.filter(targetEntities, (targetEntity) => {
2832
+ return lodash.find(relationLinks, (link) => {
2833
+ return link[relationProperty.selfIdColumnName] == row["id"] && link[relationProperty.targetIdColumnName] == targetEntity["id"];
2834
+ });
2835
+ }).map((targetEntity) => mapDbRowToEntity(server, relationModel, targetEntity, options.keepNonPropertyFields));
2836
+ }
2837
+ else {
2838
+ row[relationProperty.code] = lodash.filter(relationLinks, (link) => {
2839
+ return link[relationProperty.selfIdColumnName] == row["id"];
2840
+ }).map((link) => mapDbRowToEntity(server, relationModel, link.targetEntity, options.keepNonPropertyFields));
2841
+ }
2830
2842
  });
2831
2843
  }
2832
2844
  }
@@ -3139,8 +3151,8 @@ async function findManyRelationLinksViaLinkTable(options) {
3139
3151
  ORDER BY id
3140
3152
  `;
3141
3153
  const params = [mainEntityIds];
3142
- const links = await server.queryDatabaseObject(command, params, routeContext?.getDbTransactionClient());
3143
- const targetEntityIds = links.map((link) => link[relationProperty.targetIdColumnName]);
3154
+ const relationLinks = await server.queryDatabaseObject(command, params, routeContext?.getDbTransactionClient());
3155
+ const targetEntityIds = relationLinks.map((link) => link[relationProperty.targetIdColumnName]);
3144
3156
  const dataAccessor = server.getDataAccessor({
3145
3157
  namespace: relationModel.namespace,
3146
3158
  singularCode: relationModel.singularCode,
@@ -3178,10 +3190,10 @@ async function findManyRelationLinksViaLinkTable(options) {
3178
3190
  }
3179
3191
  }
3180
3192
  const targetEntities = await findEntities(server, dataAccessor, findEntityOptions);
3181
- lodash.forEach(links, (link) => {
3193
+ lodash.forEach(relationLinks, (link) => {
3182
3194
  link.targetEntity = lodash.find(targetEntities, (e) => e["id"] == link[relationProperty.targetIdColumnName]);
3183
3195
  });
3184
- return links;
3196
+ return { relationLinks, targetEntities };
3185
3197
  }
3186
3198
  async function findManyRelatedEntitiesViaIdPropertyCode(options) {
3187
3199
  const { server, relationProperty, mainEntityIds, selectRelationOptions } = options;
package/dist/types.d.ts CHANGED
@@ -302,6 +302,10 @@ export interface RpdDataModelProperty {
302
302
  * 当设置了 linkTableName 时,可以设置关联关系表所在的 Schema。
303
303
  */
304
304
  linkSchema?: string;
305
+ /**
306
+ * 数据字典编码。当类型为option时设置
307
+ */
308
+ dataDictionary?: string;
305
309
  /**
306
310
  * 当删除实体时,针对关系属性的联动处理。
307
311
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ruiapp/rapid-core",
3
- "version": "0.7.4",
3
+ "version": "0.7.6",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -270,19 +270,30 @@ async function findEntities(server: IRpdServer, dataAccessor: IRpdDataAccessor,
270
270
  }
271
271
 
272
272
  if (isManyRelation) {
273
- const relationLinks = await findManyRelationLinksViaLinkTable({
273
+ const selectRelationOptions: FindEntityFindManyRelationEntitiesOptions | undefined = relationOptions[relationProperty.code];
274
+ const { relationLinks, targetEntities } = await findManyRelationLinksViaLinkTable({
274
275
  server,
275
276
  routeContext,
276
277
  mainModel: relationModel,
277
278
  relationProperty,
278
279
  mainEntityIds: entityIds,
279
- selectRelationOptions: relationOptions[relationProperty.code],
280
+ selectRelationOptions,
280
281
  });
281
282
 
283
+ // 如果查询关联实体时指定了orderBy,则按照targetEntities的顺序,否则按照relationLinks的顺序。
284
+ const selectRelationOrderByOptionsSpecified = selectRelationOptions && isObject(selectRelationOptions) && selectRelationOptions.orderBy;
282
285
  forEach(rows, (row: any) => {
283
- row[relationProperty.code] = filter(relationLinks, (link: any) => {
284
- return link[relationProperty.selfIdColumnName!] == row["id"];
285
- }).map((link) => mapDbRowToEntity(server, relationModel, link.targetEntity, options.keepNonPropertyFields));
286
+ if (selectRelationOrderByOptionsSpecified) {
287
+ row[relationProperty.code] = filter(targetEntities, (targetEntity: any) => {
288
+ return find(relationLinks, (link: any) => {
289
+ return link[relationProperty.selfIdColumnName!] == row["id"] && link[relationProperty.targetIdColumnName!] == targetEntity["id"];
290
+ });
291
+ }).map((targetEntity) => mapDbRowToEntity(server, relationModel, targetEntity, options.keepNonPropertyFields));
292
+ } else {
293
+ row[relationProperty.code] = filter(relationLinks, (link: any) => {
294
+ return link[relationProperty.selfIdColumnName!] == row["id"];
295
+ }).map((link) => mapDbRowToEntity(server, relationModel, link.targetEntity, options.keepNonPropertyFields));
296
+ }
286
297
  });
287
298
  }
288
299
  } else {
@@ -628,8 +639,8 @@ async function findManyRelationLinksViaLinkTable(options: FindManyRelationEntiti
628
639
  ORDER BY id
629
640
  `;
630
641
  const params = [mainEntityIds];
631
- const links = await server.queryDatabaseObject(command, params, routeContext?.getDbTransactionClient());
632
- const targetEntityIds = links.map((link) => link[relationProperty.targetIdColumnName!]);
642
+ const relationLinks = await server.queryDatabaseObject(command, params, routeContext?.getDbTransactionClient());
643
+ const targetEntityIds = relationLinks.map((link) => link[relationProperty.targetIdColumnName!]);
633
644
 
634
645
  const dataAccessor = server.getDataAccessor({
635
646
  namespace: relationModel.namespace,
@@ -672,11 +683,11 @@ async function findManyRelationLinksViaLinkTable(options: FindManyRelationEntiti
672
683
 
673
684
  const targetEntities = await findEntities(server, dataAccessor, findEntityOptions);
674
685
 
675
- forEach(links, (link: any) => {
686
+ forEach(relationLinks, (link: any) => {
676
687
  link.targetEntity = find(targetEntities, (e: any) => e["id"] == link[relationProperty.targetIdColumnName!]);
677
688
  });
678
689
 
679
- return links;
690
+ return { relationLinks, targetEntities };
680
691
  }
681
692
 
682
693
  async function findManyRelatedEntitiesViaIdPropertyCode(options: FindManyRelationEntitiesOptions) {
package/src/types.ts CHANGED
@@ -337,6 +337,11 @@ export interface RpdDataModelProperty {
337
337
  */
338
338
  linkSchema?: string;
339
339
 
340
+ /**
341
+ * 数据字典编码。当类型为option时设置
342
+ */
343
+ dataDictionary?: string;
344
+
340
345
  /**
341
346
  * 当删除实体时,针对关系属性的联动处理。
342
347
  */