payload icon indicating copy to clipboard operation
payload copied to clipboard

Field name `id` not honored inside of `row` field

Open nathanclevenger opened this issue 1 year ago • 1 comments

Link to reproduction

No response

Describe the Bug

If a field named id is inside of a row field, it is not honored, and a _id is created in addition to a id property in the database.

To Reproduce

This configuration does not respect the id field name as the ID of the collection, with any saved documents having the id value in addition to an _id of ObjectId. (Note: this is on Mongo - I did not test this on Postgres)

export const Tags: CollectionConfig = {
  slug: 'tags',
  fields: [
    { type: 'row', fields: [
      { name: 'id',  label: 'Name', type: 'text' },
    ]},
  ],
}

While this configuration works, with the value of id actually saving in Mongo as _id

export const Tags: CollectionConfig = {
  slug: 'tags',
  fields: [
    { name: 'id',  label: 'Name', type: 'text' },
  ],
}

Payload Version

2.5.0

Adapters and Plugins

db-mongodb

nathanclevenger avatar Dec 29 '23 08:12 nathanclevenger

If we are going to allow the id field to be nested inside of a row, we should do the same for collapsible and tabs too.

This one little change is going to require a lot of changes and looping over fields. We can probably make a utility function just for getting the id field from the collection fields.

DanRibbens avatar Dec 29 '23 10:12 DanRibbens