diff --git a/src/mongoose/buildSchema.ts b/src/mongoose/buildSchema.ts index e0421fed4..c011b7d03 100644 --- a/src/mongoose/buildSchema.ts +++ b/src/mongoose/buildSchema.ts @@ -54,7 +54,7 @@ const buildSchema = (config: SanitizedConfig, configFields: Field[], buildSchema fields = { _id: idField.type === 'number' ? Number : String, }; - schemaFields = schemaFields.filter((field) => fieldAffectsData(field) && field.name !== 'id'); + schemaFields = schemaFields.filter((field) => !(fieldAffectsData(field) && field.name === 'id')); } } diff --git a/test/collections-rest/config.ts b/test/collections-rest/config.ts index e471b4499..f541effc8 100644 --- a/test/collections-rest/config.ts +++ b/test/collections-rest/config.ts @@ -101,8 +101,13 @@ export default buildConfig({ type: 'text', }, { - name: 'name', - type: 'text', + type: 'row', + fields: [ + { + name: 'name', + type: 'text', + }, + ], }, ], }, @@ -195,5 +200,21 @@ export default buildConfig({ ], }, }); + + await payload.create({ + collection: customIdSlug, + data: { + id: 'test', + name: 'inside row', + }, + }); + + await payload.create({ + collection: customIdNumberSlug, + data: { + id: 123, + name: 'name', + }, + }); }, }); diff --git a/test/collections-rest/int.spec.ts b/test/collections-rest/int.spec.ts index 270a031c2..65a3f3756 100644 --- a/test/collections-rest/int.spec.ts +++ b/test/collections-rest/int.spec.ts @@ -66,13 +66,15 @@ describe('collections-rest', () => { describe('string', () => { it('should create', async () => { const customId = `custom-${randomBytes(32).toString('hex').slice(0, 12)}`; - const { doc } = await client.create({ slug: customIdSlug, data: { id: customId, data: { name: 'custom-id-name' } } }); + const customIdName = 'custom-id-name'; + const { doc } = await client.create({ slug: customIdSlug, data: { id: customId, name: customIdName } }); expect(doc.id).toEqual(customId); + expect(doc.name).toEqual(customIdName); }); it('should find', async () => { const customId = `custom-${randomBytes(32).toString('hex').slice(0, 12)}`; - const { doc } = await client.create({ slug: customIdSlug, data: { id: customId, data: { name: 'custom-id-name' } } }); + const { doc } = await client.create({ slug: customIdSlug, data: { id: customId, name: 'custom-id-name' } }); const { doc: foundDoc } = await client.findByID({ slug: customIdSlug, id: customId }); expect(foundDoc.id).toEqual(doc.id); @@ -89,20 +91,20 @@ describe('collections-rest', () => { describe('number', () => { it('should create', async () => { const customId = Math.floor(Math.random() * (1_000_000)) + 1; - const { doc } = await client.create({ slug: customIdNumberSlug, data: { id: customId, data: { name: 'custom-id-number-name' } } }); + const { doc } = await client.create({ slug: customIdNumberSlug, data: { id: customId, name: 'custom-id-number-name' } }); expect(doc.id).toEqual(customId); }); it('should find', async () => { const customId = Math.floor(Math.random() * (1_000_000)) + 1; - const { doc } = await client.create({ slug: customIdNumberSlug, data: { id: customId, data: { name: 'custom-id-number-name' } } }); + const { doc } = await client.create({ slug: customIdNumberSlug, data: { id: customId, name: 'custom-id-number-name' } }); const { doc: foundDoc } = await client.findByID({ slug: customIdNumberSlug, id: customId }); expect(foundDoc.id).toEqual(doc.id); }); it('should update', async () => { const customId = Math.floor(Math.random() * (1_000_000)) + 1; - const { doc } = await client.create({ slug: customIdNumberSlug, data: { id: customId, data: { name: 'custom-id-number-name' } } }); + const { doc } = await client.create({ slug: customIdNumberSlug, data: { id: customId, name: 'custom-id-number-name' } }); const { doc: updatedDoc } = await client.update({ slug: customIdNumberSlug, id: doc.id, data: { name: 'updated' } }); expect(updatedDoc.name).toEqual('updated'); });