moleculer-db icon indicating copy to clipboard operation
moleculer-db copied to clipboard

Populate not working

Open achabill opened this issue 6 years ago • 3 comments

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

achabill avatar Aug 07 '19 11:08 achabill

Please create a repro example.

icebob avatar Aug 14 '19 20:08 icebob

I also see this issue in my project. I can not apply populates.

nguyenvantien2009 avatar Jun 01 '20 17:06 nguyenvantien2009

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

shafarizkyf avatar Aug 28 '20 01:08 shafarizkyf