tengo esta consulta:
const data = await modelOwners.findAll({ attributes: ["id", "name", "email"], include: [ { model: modelLotsTantiemes, as: "LotsOwner", attributes: [ "lotId", ["distributionKeyId", 'costKey'], [ Sequelize.fn('sum', Sequelize.col("tantiemeNumber")), 'totalTantieme' ], ], }, ], where: { coproNumber: req.header("customerId")}, group: ["name", "LotsOwner.distributionKeyId"], raw: true, nest: false, order: [["name", "ASC"]], });Cuando lo pruebo en Postman Y tengo este resultado:
"data": [ { "id": 4, "name": "Clement Tine", "email": "clementt@fruitsetlegumes.fr", "LotsOwner.field1": 2, "LotsOwner.field2": 1, "LotsOwner.field3": "1892" }, { "id": 6, "name": "Léo Pard", "email": "leopard@thoiry.fr", "LotsOwner.field1": 9, "LotsOwner.field2": 1, "LotsOwner.field3": "4432" }]Pero me gustaría otro nombre para mis columnas como:
"data": [ { "id": 4, "name": "Clement Tine", "email": "clementt@fruitsetlegumes.fr", "field1": 2, "field2": 1, "field3": "1892" }]No quiero el nombre del alias de la asociación. ¿Sabes si hay alguna opción para hacerlo?
Si desea tener atributos de un modelo asociado en el mismo nivel que el modelo principal, debe incluirlos manualmente indicando el nombre del modelo asociado:
const data = await modelOwners.findAll({ attributes: ["id", "name", "email", [Sequelize.col('"LotsOwner"."distributionKeyId"'), 'costKey'] ], include: [ { model: modelLotsTantiemes, as: "LotsOwner", ...