小编Roo*_*Dev的帖子

续集:如何重命名包含中的列

我有这个查询:

\n
    const data = await modelOwners.findAll({\n  attributes: ["id", "name", "email"],\n  include: [\n    {\n      model: modelLotsTantiemes,\n      as: "LotsOwner",\n      attributes: [\n        "lotId",\n        ["distributionKeyId", 'costKey'],\n        [ Sequelize.fn('sum', Sequelize.col("tantiemeNumber")), 'totalTantieme' ],\n      ],\n    },\n  ],\n  where: { coproNumber: req.header("customerId")},\n  group: ["name", "LotsOwner.distributionKeyId"],\n  raw: true,\n  nest: false,\n  order: [["name", "ASC"]],\n});\n
Run Code Online (Sandbox Code Playgroud)\n

当我在 Postman Y 上测试它时,结果如下:

\n
"data": [\n    {\n        "id": 4,\n        "name": "Clement Tine",\n        "email": "clementt@fruitsetlegumes.fr",\n        "LotsOwner.field1": 2,\n        "LotsOwner.field2": 1,\n        "LotsOwner.field3": "1892"\n    },\n    {\n        "id": 6,\n        "name": "L\xc3\xa9o Pard",\n        "email": "leopard@thoiry.fr",\n        "LotsOwner.field1": 9,\n        "LotsOwner.field2": 1,\n …
Run Code Online (Sandbox Code Playgroud)

javascript json sequelize.js

2
推荐指数
1
解决办法
3049
查看次数

标签 统计

javascript ×1

json ×1

sequelize.js ×1