【发布时间】:2021-12-08 12:22:29
【问题描述】:
我有一个包含产品、制造商和收藏品的数据库。产品和制造商之间存在 n:m 关系。在集合中,用户可以存储产品,因此产品和集合也以 n:m 关系连接。
现在我必须根据 collectionId 向制造商加载产品。
目前我有以下sn-p:
CollectionProducts.createQueryBuilder("cp")
.innerJoinAndSelect("cp.product", "product")
.leftJoinAndSelect(
Manufacturer,
"manufacturer",
"product.manufacturerId = manufacturer.id"
)
.where("cp.collectionId IN(:...ids)", { ids: collectionIds })
.getMany();
产品加载成功,但没有加载厂家。
这是打印出来的结果:
[
CollectionProducts {
collectionId: 1,
productId: 1,
__product__: Product {
id: 1,
name: 'Tea',
productImage: '',
description: 'Peach',
releaseDate: 2021-10-19T18:13:42.938Z,
status: null,
origin: 'Germany',
manufacturerId: 1
}
}
]
有人知道我在哪里做错了吗?
【问题讨论】:
标签: node.js database typescript postgresql typeorm