首页 > 解决方案 > 具有嵌套关系的 TypeORM findOne

问题描述

我在使用 TypeORM 执行嵌套查找查询时遇到一些问题。这是基本代码:

    const { completionId } = req?.params;
    const user = req.user;

    const retrievedCompletion = await getRepository(
      CompletionGoogleSearch
    ).findOne({
      relations: ['run', 'run.user'],
      where: {
        id: completionId,
        // run: { user: { id: user.id } }, // This is the code that breaks the function
      },
    });

    console.log(retrievedCompletion?.run.user.id);
    console.log(user.id);

在我看来,一切正常,查询应该运行。知道我做错了什么吗?我知道我可以通过编写查询构建器查询或使用原始 SQL 来解决这个问题——我只是想知道我的代码是否存在缺陷。

标签: javascriptnode.jspostgresqltypeorm

解决方案


typeorm 尚不支持您询问的功能(2021 年 2 月)。

查看 2018 年开放的这个问题


推荐阅读