【发布时间】:2021-03-17 05:06:56
【问题描述】:
让我们看看你能不能帮助我,因为我已经这样好几个小时了,我不能。 我正在用 Typeorm 做一些查询,情况是这样的:
我有一个 ID 数组:["array1, array1, array3"]。也就是说,在数组中,一个 id 重复了 2 次。
问题是,如果我进行这样的查询:
const found = await this.find ({
where: {id: In (Ids)},
})
发现我拥有的是:
[
Catalog {
id: 'array1',
image: 'https://image.jpg',
name: 'Article name',
description: 'Description',
price: 809,
createdAt: 2020-12-04T17:34:16.869Z,
updatedAt: 2020-12-04T17:34:16.869Z },
Catalog {
id: 'array3',
image: 'https://image.jpg',
name: 'Article name',
description: 'Description',
price: 809,
createdAt: 2020-12-04T17:34:16.869Z,
updatedAt: 2020-12-04T17:34:16.869Z }
]
而我需要的是:
[
Catalog {
id: 'array1',
image: 'https://image.jpg',
name: 'Article name',
description: 'Description',
price: 809,
createdAt: 2020-12-04T17:34:16.869Z,
updatedAt: 2020-12-04T17:34:16.869Z },
Catalog {
id: 'array1',
image: 'https://image.jpg',
name: 'Article name',
description: 'Description',
price: 809,
createdAt: 2020-12-04T17:34:16.869Z,
updatedAt: 2020-12-04T17:34:16.869Z },
Catalog {
id: 'array3',
image: 'https://image.jpg',
name: 'Article name',
description: 'Description',
price: 809,
createdAt: 2020-12-04T17:34:16.869Z,
updatedAt: 2020-12-04T17:34:16.869Z }
]
另一种选择是接下来执行一个方法,接收 ID 数组和对象的参数,迭代以获得我需要的对象数组......但我也没有找到密钥。
感谢您的帮助
【问题讨论】: