类型ORM 嵌套关系

TypeORM nested relation

提问人:Vusal Ghasanov 提问时间:11/17/2023 最后编辑:James ZVusal Ghasanov 更新时间:11/17/2023 访问量:19

问:

我对TypeORM有疑问。

    this.productRepository.createQueryBuilder('product')
    .leftJoinAndSelect('product.attributes', 'attributes')
    .leftJoin('attributes.value', 'value')
    .addSelect(['value.item AS item'])
    .getMany();

这是我的疑问。我想将嵌套值表项字段添加到属性表(实体)字段。我尝试了几种方法,但没有得到任何结果

我的预期输出是:

 "id": 1,
        "companyId": 61,
        "createdAt": "11/16/2023, 5:33:18 PM",
        "updatedAt": "11/16/2023, 5:33:18 PM",
        "attributes": [
            {
                "id": 1,
                "productId": 1,
                "name": "name",
                "item" : "John"
            },
            {
                "id": 2,
                "productId": 1,
                "name": "price",
                "item" : 15.30
            },
            {
                "id": 3,
                "productId": 1,
                "name": "stock",
                "item" : 231
            },
            {
                "id": 4,
                "productId": 1,
                "name": "color",
                "item" : "red"
            }
        ]

但我得到这个输出:

 "id": 1,
        "companyId": 61,
        "createdAt": "11/16/2023, 5:33:18 PM",
        "updatedAt": "11/16/2023, 5:33:18 PM",
        "attributes": [
            {
                "id": 1,
                "productId": 1,
                "name": "name"
            },
            {
                "id": 2,
                "productId": 1,
                "name": "price"
            },
            {
                "id": 3,
                "productId": 1,
                "name": "stock"
            },
            {
                "id": 4,
                "productId": 1,
                "name": "color"
            }
        ]
node.js nestjs 实体 类型orm

评论

1赞 Hai Alison 11/17/2023
你能提供你的实体关系吗

答: 暂无答案