如何在续集中使用UNION?或者像UNION这样的任何其他方法都可以期待promise.All ...?

Pra*_*ani 5 javascript node.js sequelize.js

我有两个表: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 + "%"
      }
    }
  }]
})
Run Code Online (Sandbox Code Playgroud)

小智 6

我知道这已经很老了,但我喜欢使用 Nodejs 来解决这个问题,因为sequelize还没有联合支持。很简单,但有时我们没有意识到这一点:

例子:

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

  • 这可行,但如果你需要限制...... (2认同)

Soh*_*war 5

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