Skip to content

Populate.keyField ignored? #51

@diegogangl

Description

@diegogangl

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 }
                ))
            )
          );
        },
      },

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions