【发布时间】:2022-08-19 06:19:26
【问题描述】:
我想展平这个查找查询结果。这是一个例子。
\"uuid\": \"5d7c5571-9f39-45ba-93d5-27f91c3322d8\",
\"type\": \"A\",
\"number\": \"00001\",
\"code\": \"978020137962\",
\"matches\": null,
\"title\": \"Generate Free Barcodes\\n\",
\"remark\": \"\",
\"detail\": null,
\"minStock\": \"0.000000\",
\"freeStock\": \"5.000000\",
\"realStock\": \"20.000000\",
\"targetStock\": \"0.000000\",
\"price\": \"156.45\",
\"minPrice\": \"85.37\",
\"recommendedPrice\": null,
\"latestPrice\": \"5.00\",
\"averagePrice\": \"51.26\",
\"bulkPrices\": null,
\"priceUnit\": \"1.000000\",
\"packageUnit\": \"1.000000\",
\"stockManagement\": true,
\"createdOn\": \"2022-07-17T18:23:41.623Z\",
\"modifiedOn\": null,
\"unit\": {
\"uuid\": \"c5327983-bc02-4350-bb45-cd3abbd2eb7d\",
\"group\": \"Length\",
\"name\": \"Foot\",
\"abbreviation\": \"ft\"
},
\"bundleChildren\": [],
\"productionChildren\": [],
\"bundleParents\": [
{
\"quantity\": \"12.000000\",
\"remark\": \"Testing child remark\",
\"bundleParent\": {
\"uuid\": \"80b82a5a-de4b-4798-a4e6-7e3064edae91\",
\"type\": \"B\",
\"number\": \"AminB1\",
\"code\": \"21\",
\"unit\": {
\"name\": \"Meter\",
\"group\": \"Length\",
\"abbreviation\": \"m\"
}
}
}
],
结果如下: \"bundleParents\": [ { \"uuid\": \"80b82a5a-de4b-4798-a4e6-7e3064edae91\", \"数量\": \"12.000000\", \"remark\": \"测试子备注\", \"类型\": \"B\", \"数字\": \"AminB1\", \"代码\": \"21\", \"单位\": \"米\", \"缩写\": \"m\" } ],
这是我在 sequelize 中的查询:
Product.findAndCountAll({
where: condition,
order: [[\'createdOn\', \'DESC\']],
limit: getLimit(req),
offset: getOffset(req),
attributes: {exclude: [\'unitId\']},
include: [
{model: Unit, as: \'unit\', attributes: {exclude: [\'createdOn\', \'modifiedOn\']}},
{model: BundleElement, as: \'bundleChildren\', attributes: [\"quantity\", \"remark\"], },
{model: ProductionElement, as: \'productionChildren\', attributes: [\"quantity\", \"remark\"]},
{model: BundleElement, as: \'bundleParents\', attributes: [\"quantity\", \"remark\"],
include: [{
model: Product, as: \"bundleParent\", attributes: [\'uuid\', \'type\', \'number\', \'code\'],
include: [{model: Unit, as: \'unit\', attributes: [\'name\', \'group\', \'abbreviation\']}]
}]
},
{model: ProductionElement, as: \'productionParents\', attributes: [\"quantity\", \"remark\"]},
],
distinct:true
})
谁能帮我这个?
标签: node.js sequelize.js