Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Populate.keyField ignored? #51

Open
diegogangl opened this issue Oct 30, 2023 · 1 comment
Open

Populate.keyField ignored? #51

diegogangl opened this issue Oct 30, 2023 · 1 comment

Comments

@diegogangl
Copy link

diegogangl commented Oct 30, 2023

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?

database/src/transform.js

Lines 186 to 190 in 3e962ec

const params = {
...(rule.params || {}),
id: values,
mapping: true,
throwIfNotExist: false

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 }
                ))
            )
          );
        },
      },
@diegogangl
Copy link
Author

It seems that error reporting sometimes also ignores FieldKey:

{
  "name": "EntityNotFoundError",
  "message": "Entity not found",
  "code": 404,
  "type": "ENTITY_NOT_FOUND",
  "data": {
    "id": "5431"
  }
}

(this is from a DELETE, note the id instead of _id)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant