Skip to content

Changing ID field using isId not working for admin-bro-mongoose #67

@christian-konrad

Description

@christian-konrad

It is a common pattern to replace the "_id" field of mongoose by the given "id" virtual when calling toObject or toJSON on a mongoose model instance to have a clean and concise API output. Using admin-bro with admin-bro-mongoose, I tried to change the id field accordingly using isId:

const adminBro = new AdminBro({
  resources: [
    {
      resource: User,
      options: {
        listProperties: ['name', 'email', 'id', 'role'],
        properties: {
          id: {
            isId: true, // <--- expect this to force adminBro to use this as the actual identifier
          },
        },
      },
    },
...

But it does not have an effect. I can not access any resource in show or edit mode or delete it via the action buttons as it fails finding the id field. It produces links like http://localhost:3000/admin/resources/User/records/show missing the id path param. After further investigation, it seems like the "_id" attribute is a hard coded constant and I could not find out if using PropertyOptions will successfully overwrite it or not: https://github.com/SoftwareBrothers/admin-bro-mongoose/blob/master/src/property.ts

Please someone fix this issue or tell me how I can change the ID field using mongoose, as I don't want to output the "_id" field in my json outputs.

Installed libraries and their versions

  • admin-bro@3.3.1
  • admin-bro-express@3.0.1
  • admin-bro-mongoose@1.1.0

Expected behavior
When setting isId: true, I expect the field to be used as the identifier for accessing the show, edit and delete actions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions