大家好,每當我使用此查詢時,我都使用帶有 sequelize 的 node-express,我得到的計數不正確。表產品包含一個產品,同時回傳計數 3。代碼如下
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]
})
產品表有 1 條記錄,但它回傳 3 條記錄。
uj5u.com熱心網友回復:
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],
})
uj5u.com熱心網友回復:
yes i also solved it
use unique:true
Product.findAndCountAll({
where:condition,
distinct:true,
unique:true,
})
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/322101.html
標籤:javascript mysql 节点.js 表达 sequelize.js
下一篇:洗掉錨標簽上的確認訊息
