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

278
Views
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 answers
Answer question

0

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

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 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!