提问人:Vusal Ghasanov 提问时间:11/17/2023 最后编辑:James ZVusal Ghasanov 更新时间:11/17/2023 访问量:19
类型ORM 嵌套关系
TypeORM nested relation
问:
我对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"
}
]
答: 暂无答案
上一个:如何在图像上找到特定点的坐标?
下一个:Typeorm 多对多关系
评论