moleculerjs / moleculerjs/database
Populate.keyField ignored?
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 33
- Forks
- 15
- Avg merge
- 15m
- Merged PRs (30d)
- 1
Description
We are trying to use the keyField parameter to use _id instead of id
_id: { type: "string", primaryKey: true },
country: {
type: "string",
required: true,
populate: {
keyField: "_id",
action: "countries.get",
},
},
But we are getting validation errors on countries.get saying that _id is undefined. Seems like id is hardcoded?
https://github.com/moleculerjs/database/blob/3e962ec89f191d8c3a4de25eb8e7cfb2390e9716/src/transform.js#L186-L190
Here's a workaround we found:
country: {
type: "string",
required: true,
populate: async (ctx, values, entities, field) => {
return Promise.all(
entities.map(
async (entity) =>
(entity.postCount = await ctx.call(
"countries.get",
{ _id: entity.country }
))
)
);
},
},
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/transform.js around lines 186-190 and trace how populate.keyField is used when building the countries.get call. Reproduce the schema with _id as the primary key; done means keyField: "_id" is honored without the validation error described in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100