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 = {
_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

@@ -100,12 +100,17 @@ export default buildConfig({
name: 'id',
type: 'text',
},
{
type: 'row',
fields: [
{
name: 'name',
type: 'text',
},
],
},
],
},
{
slug: customIdNumberSlug,
access: openAccess,
@@ -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', () => {
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');
});