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

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

Open
christian-konrad opened this issue Jan 6, 2021 · 2 comments
Open

Comments

@christian-konrad
Copy link

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

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

@lianulloa
Copy link

I am having this same issue

@lalwanikamaldev
Copy link

Any solution we found for this ?

@dziraf dziraf transferred this issue from SoftwareBrothers/adminjs Dec 28, 2021
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

3 participants