diff --git a/packages/db-postgres/src/upsertRow/insertArrays.ts b/packages/db-postgres/src/upsertRow/insertArrays.ts index 3ccbe546f4..9193389f02 100644 --- a/packages/db-postgres/src/upsertRow/insertArrays.ts +++ b/packages/db-postgres/src/upsertRow/insertArrays.ts @@ -36,7 +36,7 @@ export const insertArrays = async ({ adapter, arrays, db, parentRows }: Args): P } } - const parentID = parentRows[parentRowIndex].id + const parentID = parentRows[parentRowIndex].id || parentRows[parentRowIndex]._parentID // Add any sub arrays that need to be created // We will call this recursively below diff --git a/test/fields/collections/Array/index.ts b/test/fields/collections/Array/index.ts index 94226543f6..8c8243cb85 100644 --- a/test/fields/collections/Array/index.ts +++ b/test/fields/collections/Array/index.ts @@ -6,54 +6,62 @@ import { ArrayRowLabel } from './LabelComponent' export const arrayDefaultValue = [{ text: 'row one' }, { text: 'row two' }] const ArrayFields: CollectionConfig = { - slug: arrayFieldsSlug, admin: { enableRichTextLink: false, }, fields: [ { name: 'items', - type: 'array', - required: true, defaultValue: arrayDefaultValue, fields: [ { name: 'text', - type: 'text', required: true, + type: 'text', + }, + { + name: 'subArray', + fields: [ + { + name: 'text', + type: 'text', + }, + ], + type: 'array', }, ], + required: true, + type: 'array', }, { name: 'collapsedArray', - type: 'array', - fields: [ - { - name: 'text', - type: 'text', - required: true, - }, - ], admin: { initCollapsed: true, }, + fields: [ + { + name: 'text', + required: true, + type: 'text', + }, + ], + type: 'array', }, { name: 'localized', - type: 'array', - required: true, - localized: true, defaultValue: arrayDefaultValue, fields: [ { name: 'text', - type: 'text', required: true, + type: 'text', }, ], + localized: true, + required: true, + type: 'array', }, { - type: 'array', name: 'readOnly', admin: { readOnly: true, @@ -68,75 +76,78 @@ const ArrayFields: CollectionConfig = { ], fields: [ { - type: 'text', name: 'text', + type: 'text', }, ], + type: 'array', }, { - type: 'array', name: 'potentiallyEmptyArray', fields: [ { - type: 'text', name: 'text', + type: 'text', }, { - type: 'group', name: 'groupInRow', fields: [ { - type: 'text', name: 'textInGroupInRow', + type: 'text', }, ], + type: 'group', }, ], + type: 'array', }, { - type: 'array', name: 'rowLabelAsFunction', - fields: [ - { - name: 'title', - type: 'text', - }, - ], admin: { - description: 'Row labels rendered from a function.', components: { RowLabel: ({ data }) => data.title, }, + description: 'Row labels rendered from a function.', }, - }, - { - type: 'array', - name: 'rowLabelAsComponent', fields: [ { name: 'title', type: 'text', }, ], + type: 'array', + }, + { + name: 'rowLabelAsComponent', admin: { - description: 'Row labels rendered as react components.', components: { RowLabel: ArrayRowLabel, }, + description: 'Row labels rendered as react components.', }, + fields: [ + { + name: 'title', + type: 'text', + }, + ], + type: 'array', }, { name: 'arrayWithMinRows', - type: 'array', - minRows: 2, fields: [ { name: 'text', type: 'text', }, ], + minRows: 2, + type: 'array', }, ], + slug: arrayFieldsSlug, + versions: true, } export default ArrayFields diff --git a/test/fields/int.spec.ts b/test/fields/int.spec.ts index aa0428f1d9..4618e24490 100644 --- a/test/fields/int.spec.ts +++ b/test/fields/int.spec.ts @@ -582,6 +582,32 @@ describe('Fields', () => { expect(doc.localized).toMatchObject(arrayDefaultValue) }) + it('should create with nested array', async () => { + const subArrayText = 'something expected' + const doc = await payload.create({ + collection, + data: { + items: [ + { + subArray: [ + { + text: subArrayText, + }, + ], + text: 'test', + }, + ], + }, + }) + + const result = await payload.findByID({ + id: doc.id, + collection, + }) + + expect(result.items[0].subArray[0].text).toStrictEqual(subArrayText) + }) + it('should update without overwriting other locales with defaultValue', async () => { const localized = [{ text: 'unique' }] const enText = 'english'