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.
CodePudding user response:
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],
})
CodePudding user response:
yes i also solved it
use unique:true
Product.findAndCountAll({
where:condition,
distinct:true,
unique:true,
})