fix: missing fields in rows on custom id collections (#954)

This commit is contained in:
Dan Ribbens
2022-08-18 12:26:05 -04:00
committed by GitHub
parent 5e66e3ee78
commit 39586d3cdb
3 changed files with 31 additions and 8 deletions

View File

@@ -54,7 +54,7 @@ const buildSchema = (config: SanitizedConfig, configFields: Field[], buildSchema
fields = { fields = {
_id: idField.type === 'number' ? Number : String, _id: idField.type === 'number' ? Number : String,
}; };
schemaFields = schemaFields.filter((field) => fieldAffectsData(field) && field.name !== 'id'); schemaFields = schemaFields.filter((field) => !(fieldAffectsData(field) && field.name === 'id'));
} }
} }

View File

@@ -101,8 +101,13 @@ export default buildConfig({
type: 'text', type: 'text',
}, },
{ {
name: 'name', type: 'row',
type: 'text', 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',
},
});
}, },
}); });

View File

@@ -66,13 +66,15 @@ describe('collections-rest', () => {
describe('string', () => { describe('string', () => {
it('should create', async () => { it('should create', async () => {
const customId = `custom-${randomBytes(32).toString('hex').slice(0, 12)}`; 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.id).toEqual(customId);
expect(doc.name).toEqual(customIdName);
}); });
it('should find', async () => { it('should find', async () => {
const customId = `custom-${randomBytes(32).toString('hex').slice(0, 12)}`; 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 }); const { doc: foundDoc } = await client.findByID({ slug: customIdSlug, id: customId });
expect(foundDoc.id).toEqual(doc.id); expect(foundDoc.id).toEqual(doc.id);
@@ -89,20 +91,20 @@ describe('collections-rest', () => {
describe('number', () => { describe('number', () => {
it('should create', async () => { it('should create', async () => {
const customId = Math.floor(Math.random() * (1_000_000)) + 1; 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); expect(doc.id).toEqual(customId);
}); });
it('should find', async () => { it('should find', async () => {
const customId = Math.floor(Math.random() * (1_000_000)) + 1; 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 }); const { doc: foundDoc } = await client.findByID({ slug: customIdNumberSlug, id: customId });
expect(foundDoc.id).toEqual(doc.id); expect(foundDoc.id).toEqual(doc.id);
}); });
it('should update', async () => { it('should update', async () => {
const customId = Math.floor(Math.random() * (1_000_000)) + 1; 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' } }); const { doc: updatedDoc } = await client.update({ slug: customIdNumberSlug, id: doc.id, data: { name: 'updated' } });
expect(updatedDoc.name).toEqual('updated'); expect(updatedDoc.name).toEqual('updated');
}); });