如何在续集中使用 UNION.??或任何其他方法,如 UNION 期望承诺.都.?



我有两个表:tbl_producttbl_product_category

我想制作一个接受关键字并返回与关键字匹配的所有产品和产品类别的 API。 如果结果来自tbl_product那么它也返回它是产品。 如果结果来自tbl_product_category则它还返回它是类别。

tbl_product_catagory.findAll({
raw: true,
attributes: [[sequelize.literal("catagory_name"), "type"]],
include: [{
model: tbl_product,
attributes: [[sequelize.literal(["product_name"]), "name"]],
required: false,
where: {
product_name: {
[Op.like]: "%" + data.word + "%"
}
}
}]
})

我知道这已经很老了,但我喜欢展示使用 nodejs 解决这个问题的转变,因为续集还没有联合支持。非常简单,但有时我们没有意识到这一点:

例:

Promise.all([
Blog.findAll({ include: { model: Author, required: true } }),
Blog.findAll({ include: { model: AnonymInfo, required: true } }),
]).then((modelReturn) => resolve(modelReturn.flat()))

根据这个答案和这个答案,我们可以得出结论,续集对工会没有很好的支持。

最新更新