Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

676
Vistas
sequelize : how rename column in include

I have this query :

    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"]],
});

When I test it on Postman Y have this result :

"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"
    }]

But I would like an other name for my columns like :

"data": [
    {
        "id": 4,
        "name": "Clement Tine",
        "email": "clementt@fruitsetlegumes.fr",
        "field1": 2,
        "field2": 1,
        "field3": "1892"
    }]
  

I don't want the name of the association alias. Do you know if there is an option to do it ?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If you wish to have attributes of an associated model on the same level as the main model then you need to include them manually indicating the associated model name:

const data = await modelOwners.findAll({
  attributes: ["id", "name", "email",
  [Sequelize.col('"LotsOwner"."distributionKeyId"'), 'costKey']
  ],
  include: [
    {
      model: modelLotsTantiemes,
      as: "LotsOwner",
...
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda