我有这个查询:
\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});\nRun 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)