浏览代码

add refPath

lrf 2 年之前
父节点
当前提交
f04172ea5a
共有 1 个文件被更改,包括 5 次插入5 次删除
  1. 5 5
      lib/service/crud-service.js

+ 5 - 5
lib/service/crud-service.js

@@ -128,7 +128,7 @@ class CrudService extends NafService {
     if (sort && isString(sort)) {
       sort = { [sort]: desc ? -1 : 1 };
     } else if (sort && isArray(sort)) {
-      sort = sort.map((f) => ({ [f]: desc ? -1 : 1 })).reduce((p, c) => ({ ...p, ...c }), {});
+      sort = sort.map(f => ({ [f]: desc ? -1 : 1 })).reduce((p, c) => ({ ...p, ...c }), {});
     }
     let res = await this.model.findOne(filter, projection).exec();
     res = await this.afterFetch(filter, res);
@@ -147,7 +147,7 @@ class CrudService extends NafService {
     if (sort && isString(sort)) {
       sort = { [sort]: desc ? -1 : 1 };
     } else if (sort && isArray(sort)) {
-      sort = sort.map((f) => ({ [f]: desc ? -1 : 1 })).reduce((p, c) => ({ ...p, ...c }), {});
+      sort = sort.map(f => ({ [f]: desc ? -1 : 1 })).reduce((p, c) => ({ ...p, ...c }), {});
     }
     let condition = cloneDeep(filter);
     condition = await this.beforeQuery(condition);
@@ -170,12 +170,12 @@ class CrudService extends NafService {
 
     // 过滤出ref字段
     const refMods = await this.getRefMods();
-    const populate = refMods.map((i) => i.col);
+    const populate = refMods.map(i => i.col);
     // 带ref查询
     let rs = await this.model.find(trimData(condition), projection, { skip, limit, sort }).populate(populate).exec();
     rs = JSON.parse(JSON.stringify(rs));
     // 整理ref数据
-    rs = rs.map((i) => {
+    rs = rs.map(i => {
       for (const obj of refMods) {
         const { col, prop, type } = obj;
         if (!prop) continue;
@@ -206,7 +206,7 @@ class CrudService extends NafService {
     const mod = await this.getModel();
     const refMods = [];
     for (const key in mod) {
-      if (!mod[key].ref) continue;
+      if (!mod[key].ref && !mod[key].refPath) continue;
       refMods.push({ col: key, prop: mod[key].getProp, type: mod[key].type.name });
     }
     return refMods;