moleculer-db
moleculer-db copied to clipboard
Populate not working
Models
//Criteria
{
amount: {type: Number},
limit: {type: Number}
},
//Pool
{
criteriaId: {
type: Schema.Types.ObjectId,
ref: "Criteria",
}
}
Pool service(settings)
settings: {
fields: ['criteriaId'],
populates: {
// NOT working
criteriaId(ids, pools, rule, ctx) {
return this.Promise.all(pools.map(async pool => pool.criteria = await ctx.call("pools.get", {
id: pool._id.toString()
})));
}
//NOT working
"criteriaId": {
action: "criterias.get",
params: {
fields: ["amount", "limit"]
}
},
//NOT working
"criteriaId": "criterias.get"
},
},
Pool service(list action)
let pools = await this.adapter.find({ populate: ['criteriaId']});
I 've gone through several issues here but cannot get this to work
Please create a repro example.
I also see this issue in my project. I can not apply populates.
any update from this? have similar issue, I use moleculer-db-adapter-sequelize, my code looks something like this
settings: {
populates: {
customerType: "customer_types.get",
fieldOfWork(ids){
this.logger.info("fieldOfWork", ids);
return Promise.resolve("fieldOfWork");
}
}
}
if I request: /customer, there is customerType with id value, but if my requst: /custumer?populate=customerType, the customerType field is missing, I suppose to be customer data object