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

274
Vistas
sequelize node express javascript

hi every one i am using node-express with sequelize whenever i use this query i am getting incorrect count. Tabel product contain One product while it's returning count 3. code is below

let product = await model.Product.findAndCountAll({
    where:condition, 
    attributes:['id' , 'product_name' , 'description' , 'model_information' , 'brand', 'ProductWarrenty' , 'WarrentyDuration' , [price ,'price']],
    include:[{
      model:model.Category,as:'productcategory'
      
    } , {
      model:model.SubCategory, as:'ProductSubCategory'
    } , {
      model:model.ProductImages,as:'product_images'
    }],
    offset: offset,
      limit: 14,
      order: [sorting]
  })

product table has 1 record but it is returning 3 records.

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

0

yes i also solved it 
use unique:true 
Product.findAndCountAll({
        where:condition, 
distinct:true,
unique:true,
})
about 4 years ago · Juan Pablo Isaza Denunciar

0

yeah i solved it.
use two properties
    unique:true,
    distinct:true,
use this query 

et product = await model.Product.findAndCountAll({
        where:condition, 
distinct:true,
unique:true,
        attributes:['id' , 'product_name' , 'description' , 'model_information' , 'brand', 'ProductWarrenty' , 'WarrentyDuration' , [price ,'price']],
        include:[{
          model:model.Category,as:'productcategory'
          
        } , {
          model:model.SubCategory, as:'ProductSubCategory'
        } , {
          model:model.ProductImages,as:'product_images'
        }],
        offset: offset,
          limit: 14,
          order: [sorting],
      })
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