Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

322
Views
Postgres: Sequelize Group, no funciona cuando se hace referencia a la columna de la tabla de inclusión

Este es mi código, realmente ya no sé cómo solucionar este problema.

cuando ingreso este código.

 db.models.Price.findAll({ attributes:['id', 'item.item_name'], group: [ ['masterfile_price.id','item.id','item.item_name'] ], // [sequelize.literal('Item.item_name')] // ['masterfile_price.id'] raw: true, include: [{ model: db.models.Item, as: 'item', attributes: ['id',"item_name"], }], })

Me dará este error error DatabaseError [SequelizeDatabaseError]: la columna "item.item_name" debe aparecer en la cláusula GROUP BY o usarse en una función agregada, no sé por qué

la consulta es esta

 SELECT "masterfile_price"."id", "item"."item_name", "item"."id" AS "item.id", "item"."item_name" AS "item.item_name" FROM "masterfile_prices" AS "masterfile_price" LEFT OUTER JOIN "masterfile_items" AS "item" ON "masterfile_price"."itemId" = "item"."id" GROUP BY "masterfile_price"."id";

el problema es que solo quiero el item_name

en mi consulta original sin usar secuencial está funcionando esto

 SELECT "item"."item_name" AS "item.item_name" FROM "masterfile_prices" AS "masterfile_price" LEFT OUTER JOIN "masterfile_items" AS "item" ON "masterfile_price"."itemId" = "item"."id" GROUP BY item.item_name;

cuales serán los resultados de

item.item_name
prueba9
prueba10

No sé por qué no puedo replicarlo, en secuela, ¿o me estoy perdiendo algo?

o hay algo malo con secuenciar grupo por

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

opción de group debe ser una string | Fn | Col o una matriz de string | Fn | Col . Por lo tanto, debe eliminar los corchetes adicionales:

 group: ['masterfile_price.id','item.id','item.item_name']

Si desea seleccionar y agrupar solo por item.item_name , debe indicarlo solo en los attributes y en las opciones de group :

 db.models.Price.findAll({ attributes:[[Sequelize.col('item.item_name'), 'item_name']], group: Sequelize.col('item.item_name'), raw: true, include: [{ model: db.models.Item, as: 'item', attributes: [], }], })
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!