我有一个boq模型
喜欢:
var BOQSchema = new Schema({
name: String,
products: [{ product: { type: Schema.ObjectId, ref: 'Product' }, config: {} }],
}
和产品型号如下: -
var ProductSchema = new Schema({
name: String,
ratecard: [{ type: Schema.ObjectId, ref: "RateCard"}]
});
然后是价目表模型
var RateCardSchema = new Schema({
name: String
});
现在在BOQ的电话中,我想填充产品的产品和价目表
这就是我的尝试但不是如此
exports.getById = function (req, res) {
var populate_fields = [
{
path: 'products.product',
model: 'Product',
populate:{
path: 'products.product.ratecard',
model: 'RateCard'
}
},
{
path: 'customer',
model: dbSchema.ab_customers
},
{
path: 'location',
model: dbSchema.ab_city
}
]
BOQ.findOne({ _id: req.params.id, isDeleted: false }).populate(populate_fields).exec(function (err, data) {
if (err) { return res.send(err); }
if (!data) { return res.json(401); }
res.status(200).json({ boq: data });
});
};