[loopbackjs]如何在(选择xxx)查询中不执行的操作

问题描述 投票:0回答:1

[我很乐意使用Loopback 4 whereBuilder来构建一个查询,例如'从不在其中的ID中选择文件*(从workFile ='xxxxx'的workFile中选择fileId'),然后尝试以下操作:

const fileIdArray = await this.workFileRepository.find({
      where: {
        fileId: {
          eq: xxx
        }
      }
    });
    const ret = await this.fileRepository.find({
      where: {
        id: {
          nin: fileIdArray
        }
      }
    })

const ret = await this.fileRepository.find({
      where: {
        id: {
          nin: () => {
            return await this.workFileRepository.find({
              where: {
                fileId: {
                  eq: id
                }
              }
            })
          }
        }
      }
    })

但是他们两个都错了,我该怎么办?这是错误:

error TS2345: Argument of type '{ where: { id: { nin: () => (WorkFile & WorkFileRelations)[]; }; }; }' is not assignable to parameter of type 'Filter<File>'.
  Types of property 'where' are incompatible.
    Type '{ id: { nin: () => (WorkFile & WorkFileRelations)[]; }; }' is not assignable to type 'Condition<File> | AndClause<File> | OrClause<File> | undefined'.
      Type '{ id: { nin: () => (WorkFile & WorkFileRelations)[]; }; }' is not assignable to type 'Condition<File>'.
        Types of property 'id' are incompatible.
          Type '{ nin: () => (WorkFile & WorkFileRelations)[]; }' is not assignable to type 'string | (string & Date) | PredicateComparison<string> | undefined'.
            Type '{ nin: () => (WorkFile & WorkFileRelations)[]; }' is not assignable to type 'PredicateComparison<string>'.
              Types of property 'nin' are incompatible.
                Type '() => (WorkFile & WorkFileRelations)[]' is missing the following properties from type 'string[]': pop, push, concat, join, and 25 more.

 86     const ret = await this.fileRepository.find({
                                                   ~
 87       where: {

正确的格式是这样的:

const ret = await this.fileRepository.find({
      where: {
        id: {
          nin: ["xxxxxx2","xxxxxx3"]
        }
      }
    })

但是如果我改为

const ret = await this.fileRepository.find({
      where: {
        id: {
          nin: ()=>{
            return ['xxxxx2','xxxx3']
          }
        }
      }
    })

错了,我不知道是否有人知道并使用此框架

loopbackjs loopback
1个回答
0
投票

我找到了解决方案,首先我获取了包含的ID:

const inqFileCollectionss = await this.workFileRepository.find({
      where: {
        workId: {
          eq: id
        }
      }
    });
    const inqFileIds = inqFileCollectionss.map(item => item.fileId)

然后我这样获取:

 const data = await this.fileRepository.find({
      where: {
        id: {
          nin: inqFileIds
        }
      },
      limit: pageSize,
      skip: pageIndex
    })
© www.soinside.com 2019 - 2024. All rights reserved.