diff --git a/packages/db-postgres/src/find/buildFindManyArgs.ts b/packages/db-postgres/src/find/buildFindManyArgs.ts index f6b4f8ee4a..e0d4224343 100644 --- a/packages/db-postgres/src/find/buildFindManyArgs.ts +++ b/packages/db-postgres/src/find/buildFindManyArgs.ts @@ -1,19 +1,13 @@ -import { ArrayField, Block } from 'payload/types'; -import toSnakeCase from 'to-snake-case'; -import { SanitizedCollectionConfig } from 'payload/dist/collections/config/types'; -import { SanitizedConfig } from 'payload/config'; +import { ArrayField, Block, Field } from 'payload/types'; import { DBQueryConfig } from 'drizzle-orm'; import { traverseFields } from './traverseFields'; -import { buildWithFromDepth } from './buildWithFromDepth'; import { PostgresAdapter } from '../types'; type BuildFindQueryArgs = { adapter: PostgresAdapter - config: SanitizedConfig - collection: SanitizedCollectionConfig depth: number - fallbackLocale?: string | false - locale?: string + fields: Field[] + tableName: string } export type Result = DBQueryConfig<'many', true, any, any> @@ -22,11 +16,9 @@ export type Result = DBQueryConfig<'many', true, any, any> // a collection field structure export const buildFindManyArgs = ({ adapter, - config, - collection, depth, - fallbackLocale, - locale, + fields, + tableName, }: BuildFindQueryArgs): Record => { const result: Result = { with: {}, @@ -39,8 +31,6 @@ export const buildFindManyArgs = ({ }, }; - const tableName = toSnakeCase(collection.slug); - if (adapter.tables[`${tableName}_relationships`]) { result.with._relationships = { orderBy: ({ order }, { asc }) => [asc(order)], @@ -48,13 +38,6 @@ export const buildFindManyArgs = ({ id: false, parent: false, }, - with: buildWithFromDepth({ - adapter, - config, - depth, - fallbackLocale, - locale, - }), }; } @@ -67,11 +50,10 @@ export const buildFindManyArgs = ({ traverseFields({ adapter, - config, currentArgs: result, currentTableName: tableName, depth, - fields: collection.fields, + fields, _locales, locatedArrays, locatedBlocks, diff --git a/packages/db-postgres/src/find/traverseFields.ts b/packages/db-postgres/src/find/traverseFields.ts index e644f80230..7556220e43 100644 --- a/packages/db-postgres/src/find/traverseFields.ts +++ b/packages/db-postgres/src/find/traverseFields.ts @@ -1,5 +1,4 @@ /* eslint-disable no-param-reassign */ -import { SanitizedConfig } from 'payload/config'; import toSnakeCase from 'to-snake-case'; import { fieldAffectsData } from 'payload/dist/fields/config/types'; import { ArrayField, Block, Field } from 'payload/types'; @@ -8,7 +7,6 @@ import { PostgresAdapter } from '../types'; type TraverseFieldArgs = { adapter: PostgresAdapter - config: SanitizedConfig, currentArgs: Record, currentTableName: string depth?: number, @@ -23,7 +21,6 @@ type TraverseFieldArgs = { export const traverseFields = ({ adapter, - config, currentArgs, currentTableName, depth, @@ -55,7 +52,6 @@ export const traverseFields = ({ traverseFields({ adapter, - config, currentArgs: withArray, currentTableName: arrayTableName, depth, @@ -89,7 +85,6 @@ export const traverseFields = ({ traverseFields({ adapter, - config, currentArgs: withBlock, currentTableName, depth, @@ -109,7 +104,6 @@ export const traverseFields = ({ case 'group': traverseFields({ adapter, - config, currentArgs, currentTableName, depth, diff --git a/packages/db-postgres/src/findOne.ts b/packages/db-postgres/src/findOne.ts index 4a5d94c214..26c8483c9c 100644 --- a/packages/db-postgres/src/findOne.ts +++ b/packages/db-postgres/src/findOne.ts @@ -24,11 +24,9 @@ export const findOne: FindOne = async function findOne({ const findManyArgs = buildFindManyArgs({ adapter: this, - config: this.payload.config, - collection: collectionConfig, depth: 0, - fallbackLocale: req.fallbackLocale, - locale: req.locale, + fields: collectionConfig.fields, + tableName, }); findManyArgs.where = query; diff --git a/packages/db-postgres/src/transform/write/traverseFields.ts b/packages/db-postgres/src/transform/write/traverseFields.ts index 4139df165d..bfe53d936c 100644 --- a/packages/db-postgres/src/transform/write/traverseFields.ts +++ b/packages/db-postgres/src/transform/write/traverseFields.ts @@ -46,57 +46,29 @@ export const traverseFields = ({ row, }: Args) => { fields.forEach((field) => { - let targetRow = row; let columnName = ''; let fieldData: unknown; if (fieldAffectsData(field)) { columnName = `${columnPrefix || ''}${field.name}`; - - // If the field is localized, we need to access its data based on the - // locale being inserted - if (field.localized || forceLocalized) { - if (!locales[locale]) locales[locale] = {}; - targetRow = locales[locale]; - - if (typeof fieldData === 'object' && fieldData !== null) { - Object.entries(fieldData).forEach(([fieldLocale, fieldLocaleData]) => { - // If this is the locale being created / updated, - // set the field data equal to this locale's data - if (fieldLocale === locale) { - if (typeof fieldData[locale] !== 'undefined') { - fieldData = fieldData[locale]; - } - } else { - // Otherwise, transform the locale row and store it - } - }); - } - } else { - fieldData = data[field.name]; - } + fieldData = data[field.name]; } - switch (field.type) { - case 'number': { - // TODO: handle hasMany - targetRow[columnName] = fieldData; - break; - } - - case 'select': { - break; - } - - case 'array': { - const arrayTableName = `${newTableName}_${toSnakeCase(field.name)}`; - if (!arrays[arrayTableName]) arrays[arrayTableName] = []; + if (field.type === 'array') { + const arrayTableName = `${newTableName}_${toSnakeCase(field.name)}`; + if (!arrays[arrayTableName]) arrays[arrayTableName] = []; + if (field.localized) { + if (typeof data[field.name] === 'object' && data[field.name] !== null) { + // loop over each locale + console.log(data[field.name]); + } + } else { const newRows = transformArray({ arrayTableName, blocks, columnName, - data: fieldData, + data: data[field.name], field, locale, path, @@ -104,193 +76,237 @@ export const traverseFields = ({ }); arrays[arrayTableName] = arrays[arrayTableName].concat(newRows); - - break; } - case 'blocks': { - if (isArrayOfRows(fieldData)) { - fieldData.forEach((blockRow, i) => { - if (typeof blockRow.blockType !== 'string') return; - const matchedBlock = field.blocks.find(({ slug }) => slug === blockRow.blockType); - if (!matchedBlock) return; + return; + } - if (!blocks[blockRow.blockType]) blocks[blockRow.blockType] = []; - - const newRow: BlockRowToInsert = { - arrays: {}, - row: { - _order: i + 1, - _path: `${path}${field.name}`, - }, - locales: {}, - }; - - if (field.localized) newRow.row._locale = locale; - - const blockTableName = `${newTableName}_${toSnakeCase(blockRow.blockType)}`; - - traverseFields({ - arrays: newRow.arrays, - blocks, - columnPrefix: '', - data: blockRow, - fields: matchedBlock.fields, - locale, - locales: newRow.locales, - newTableName: blockTableName, - parentTableName: blockTableName, - path: `${path || ''}${field.name}.${i}.`, - relationships, - row: newRow.row, - }); - - blocks[blockRow.blockType].push(newRow); - }); - } - - break; - } - - case 'group': { + if (field.type === 'blocks') { + if (field.localized) { if (typeof data[field.name] === 'object' && data[field.name] !== null) { - let targetData = data[field.name]; - if (field.localized && typeof data[field.name][locale] === 'object' && data[field.name][locale] !== null) { - targetData = data[field.name][locale]; - } + // loop over each locale + console.log(data[field.name]); + } + } else if (isArrayOfRows(fieldData)) { + fieldData.forEach((blockRow, i) => { + if (typeof blockRow.blockType !== 'string') return; + const matchedBlock = field.blocks.find(({ slug }) => slug === blockRow.blockType); + if (!matchedBlock) return; + + if (!blocks[blockRow.blockType]) blocks[blockRow.blockType] = []; + + const newRow: BlockRowToInsert = { + arrays: {}, + row: { + _order: i + 1, + _path: `${path}${field.name}`, + }, + locales: {}, + }; + + if (field.localized) newRow.row._locale = locale; + + const blockTableName = `${newTableName}_${toSnakeCase(blockRow.blockType)}`; traverseFields({ - arrays, + arrays: newRow.arrays, blocks, - columnPrefix: `${columnName}_`, - data: targetData as Record, - existingLocales, - fields: field.fields, - forceLocalized: field.localized, + columnPrefix: '', + data: blockRow, + fields: matchedBlock.fields, locale, - locales, - newTableName: `${parentTableName}_${toSnakeCase(field.name)}`, - parentTableName, - path: `${path || ''}${field.name}.`, + locales: newRow.locales, + newTableName: blockTableName, + parentTableName: blockTableName, + path: `${path || ''}${field.name}.${i}.`, relationships, - row, + row: newRow.row, + }); + + blocks[blockRow.blockType].push(newRow); + }); + } + + return; + } + + if (field.type === 'group') { + if (typeof data[field.name] === 'object' && data[field.name] !== null) { + let targetData = data[field.name]; + if (field.localized && typeof data[field.name][locale] === 'object' && data[field.name][locale] !== null) { + targetData = data[field.name][locale]; + } + + traverseFields({ + arrays, + blocks, + columnPrefix: `${columnName}_`, + data: targetData as Record, + existingLocales, + fields: field.fields, + forceLocalized: field.localized, + locale, + locales, + newTableName: `${parentTableName}_${toSnakeCase(field.name)}`, + parentTableName, + path: `${path || ''}${field.name}.`, + relationships, + row, + }); + } + + return; + } + + if (field.type === 'relationship') { + const baseRelationRow: Record = { + path: `${path || ''}${field.name}`, + }; + + if (field.localized && typeof fieldData === 'object') { + if (locale in fieldData) { + baseRelationRow.locale = locale; + fieldData = fieldData[locale]; + } else { + return; + } + } + + const relations = Array.isArray(fieldData) ? fieldData : [fieldData]; + + relations.forEach((relation, i) => { + if (relation) { + const relationRow = { ...baseRelationRow }; + if ('hasMany' in field && field.hasMany) relationRow.order = i + 1; + + if (Array.isArray(field.relationTo) && valueIsValueWithRelation(relation)) { + relationRow[`${relation.relationTo}ID`] = relation.value; + relationships.push(relationRow); + } else { + relationRow[`${field.relationTo}ID`] = relation; + if (relation) relationships.push(relationRow); + } + } + }); + + return; + } + + if (fieldAffectsData(field)) { + const valuesToTransform: { localeKey?: string, ref: unknown, value: unknown }[] = []; + + if ((field.localized || forceLocalized)) { + if (typeof fieldData === 'object' && fieldData !== null) { + Object.entries(fieldData).forEach(([localeKey, localeData]) => { + if (!locales[localeKey]) locales[localeKey] = {}; + + valuesToTransform.push({ + localeKey, + ref: locales, + value: localeData, + }); }); } - - break; + } else { + valuesToTransform.push({ value: fieldData, ref: row }); } - case 'date': { - if (typeof fieldData === 'string') { - const parsedDate = new Date(fieldData); - targetRow[columnName] = parsedDate; - } + valuesToTransform.forEach(({ localeKey, ref, value }) => { + if (typeof value !== 'undefined') { + let formattedValue = value; - break; - } + switch (field.type) { + case 'number': { + // TODO: handle hasMany + break; + } - // case 'tabs': { - // await Promise.all(field.tabs.map(async (tab) => { - // if ('name' in tab) { - // if (typeof data[tab.name] === 'object' && data[tab.name] !== null) { - // await traverseFields({ - // adapter, - // arrayRowPromises, - // blockRows, - // columnPrefix: `${columnName}_`, - // data: data[tab.name] as Record, - // fields: tab.fields, - // locale, - // localeRow, - // operation, - // path: `${path || ''}${tab.name}.`, - // relationshipRows, - // row, - // tableName, - // }); - // } - // } else { - // await traverseFields({ - // adapter, - // arrayRowPromises, - // blockRows, - // columnPrefix, - // data, - // fields: tab.fields, - // locale, - // localeRow, - // operation, - // path, - // relationshipRows, - // row, - // tableName, - // }); - // } - // })); - // break; - // } + case 'select': { + break; + } - // case 'row': - // case 'collapsible': { - // await traverseFields({ - // adapter, - // arrayRowPromises, - // blockRows, - // columnPrefix, - // data, - // fields: field.fields, - // locale, - // localeRow, - // operation, - // path, - // relationshipRows, - // row, - // tableName, - // }); - // break; - // } - - case 'relationship': - case 'upload': { - const relations = Array.isArray(fieldData) ? fieldData : [fieldData]; - - relations.forEach((relation, i) => { - if (relation) { - const relationRow: Record = { - path: `${path || ''}${field.name}`, - }; - - if ('hasMany' in field && field.hasMany) relationRow.order = i + 1; - if (field.localized) { - relationRow.locale = locale; - - if (Array.isArray(field.relationTo) && valueIsValueWithRelation(relation)) { - relationRow[`${relation.relationTo}ID`] = relation.value; - relationships.push(relationRow); - } else { - relationRow[`${field.relationTo}ID`] = relation; - if (relation) relationships.push(relationRow); + case 'date': { + if (typeof fieldData === 'string') { + const parsedDate = new Date(fieldData); + formattedValue = parsedDate; } - } else if (Array.isArray(field.relationTo) && valueIsValueWithRelation(relation)) { - relationRow[`${relation.relationTo}ID`] = relation.value; - relationships.push(relationRow); - } else { - relationRow[`${field.relationTo}ID`] = relation; - if (relation) relationships.push(relationRow); + + break; + } + + // case 'tabs': { + // await Promise.all(field.tabs.map(async (tab) => { + // if ('name' in tab) { + // if (typeof data[tab.name] === 'object' && data[tab.name] !== null) { + // await traverseFields({ + // adapter, + // arrayRowPromises, + // blockRows, + // columnPrefix: `${columnName}_`, + // data: data[tab.name] as Record, + // fields: tab.fields, + // locale, + // localeRow, + // operation, + // path: `${path || ''}${tab.name}.`, + // relationshipRows, + // row, + // tableName, + // }); + // } + // } else { + // await traverseFields({ + // adapter, + // arrayRowPromises, + // blockRows, + // columnPrefix, + // data, + // fields: tab.fields, + // locale, + // localeRow, + // operation, + // path, + // relationshipRows, + // row, + // tableName, + // }); + // } + // })); + // break; + // } + + // case 'row': + // case 'collapsible': { + // await traverseFields({ + // adapter, + // arrayRowPromises, + // blockRows, + // columnPrefix, + // data, + // fields: field.fields, + // locale, + // localeRow, + // operation, + // path, + // relationshipRows, + // row, + // tableName, + // }); + // break; + // } + + default: { + break; } } - }); - - break; - } - - default: { - if (typeof fieldData !== 'undefined') { - targetRow[columnName] = fieldData; + if (localeKey) { + ref[localeKey][columnName] = formattedValue; + } else { + ref[columnName] = formattedValue; + } } - break; - } + }); } }); }; diff --git a/packages/db-postgres/src/upsertRow/index.ts b/packages/db-postgres/src/upsertRow/index.ts index aa1182b521..291b43dec5 100644 --- a/packages/db-postgres/src/upsertRow/index.ts +++ b/packages/db-postgres/src/upsertRow/index.ts @@ -1,11 +1,13 @@ /* eslint-disable no-param-reassign */ +import { eq } from 'drizzle-orm'; import { transform } from '../transform/read'; import { BlockRowToInsert } from '../transform/write/types'; -import { insertArrays } from '../insertArrays'; +import { insertArrays } from './insertArrays'; import { transformForWrite } from '../transform/write'; import { Args } from './types'; import { deleteExistingRowsByPath } from './deleteExistingRowsByPath'; import { deleteExistingArrayRows } from './deleteExistingArrayRows'; +import { buildFindManyArgs } from '../find/buildFindManyArgs'; export const upsertRow = async ({ adapter, @@ -89,23 +91,20 @@ export const upsertRow = async ({ // INSERT LOCALES // ////////////////////////////////// - let insertedLocaleRow: Record; - if (localeToInsert) { const localeTable = adapter.tables[`${tableName}_locales`]; promises.push(async () => { if (operation === 'update') { - [insertedLocaleRow] = await adapter.db.insert(localeTable) + await adapter.db.insert(localeTable) .values(localeToInsert) .onConflictDoUpdate({ target: [localeTable._locale, localeTable._parentID], set: localeToInsert, - }) - .returning(); + }); } else { - [insertedLocaleRow] = await adapter.db.insert(localeTable) - .values(localeToInsert).returning(); + await adapter.db.insert(localeTable) + .values(localeToInsert); } }); } @@ -114,8 +113,6 @@ export const upsertRow = async ({ // INSERT RELATIONSHIPS // ////////////////////////////////// - let insertedRelationshipRows: Record[]; - if (relationsToInsert.length > 0) { promises.push(async () => { const relationshipsTableName = `${tableName}_relationships`; @@ -132,7 +129,7 @@ export const upsertRow = async ({ }); } - insertedRelationshipRows = await adapter.db.insert(adapter.tables[relationshipsTableName]) + await adapter.db.insert(adapter.tables[relationshipsTableName]) .values(relationsToInsert).returning(); }); } @@ -182,12 +179,8 @@ export const upsertRow = async ({ }, []); if (blockLocaleRowsToInsert.length > 0) { - const insertedBlockLocaleRows = await adapter.db.insert(adapter.tables[`${tableName}_${blockName}_locales`]) + await adapter.db.insert(adapter.tables[`${tableName}_${blockName}_locales`]) .values(blockLocaleRowsToInsert).returning(); - - insertedBlockLocaleRows.forEach((blockLocaleRow, i) => { - insertedBlockRows[blockName][blockLocaleIndexMap[i]]._locales = [blockLocaleRow]; - }); } await insertArrays({ @@ -224,20 +217,28 @@ export const upsertRow = async ({ await Promise.all(promises.map((promise) => promise())); + // ////////////////////////////////// + // RETRIEVE NEWLY UPDATED ROW + // ////////////////////////////////// + + const findManyArgs = buildFindManyArgs({ + adapter, + depth: 0, + fields, + tableName, + }); + + findManyArgs.where = eq(adapter.tables[tableName].id, insertedRow.id); + + const doc = await adapter.db.query[tableName].findFirst(findManyArgs); + // ////////////////////////////////// // TRANSFORM DATA // ////////////////////////////////// - if (insertedLocaleRow) insertedRow._locales = [insertedLocaleRow]; - if (insertedRelationshipRows?.length > 0) insertedRow._relationships = insertedRelationshipRows; - - Object.entries(insertedBlockRows).forEach(([blockName, blocks]) => { - if (blocks.length > 0) insertedRow[`_blocks_${blockName}`] = blocks; - }); - const result = transform({ config: adapter.payload.config, - data: insertedRow, + data: doc, fields, }); diff --git a/packages/db-postgres/src/insertArrays.ts b/packages/db-postgres/src/upsertRow/insertArrays.ts similarity index 50% rename from packages/db-postgres/src/insertArrays.ts rename to packages/db-postgres/src/upsertRow/insertArrays.ts index 5f3a75cba5..89bc1181da 100644 --- a/packages/db-postgres/src/insertArrays.ts +++ b/packages/db-postgres/src/upsertRow/insertArrays.ts @@ -1,6 +1,6 @@ /* eslint-disable no-param-reassign */ -import { PostgresAdapter } from './types'; -import { ArrayRowToInsert } from './transform/write/types'; +import { PostgresAdapter } from '../types'; +import { ArrayRowToInsert } from '../transform/write/types'; type Args = { adapter: PostgresAdapter @@ -15,19 +15,11 @@ type RowsByTable = { arrays: { [tableName: string]: ArrayRowToInsert[] }[] - columnName: string - localeRowIndexMap: [number, number][] locales: Record[] - rowIndexMap: [number, number][] rows: Record[] } } -// We want to insert ALL array rows per table with a single insertion -// rather than inserting each array row separately. -// To do this, we take in an array of arrays by table name and parent rows -// Parent rows and the array of arrays need to be the same length -// so we can "hoist" the created array rows back into the parent rows export const insertArrays = async ({ adapter, arrays, @@ -41,26 +33,17 @@ export const insertArrays = async ({ // If the table doesn't exist in map, initialize it if (!rowsByTable[tableName]) { rowsByTable[tableName] = { - columnName: arrayRows[0]?.columnName, arrays: [], - localeRowIndexMap: [], locales: [], - rowIndexMap: [], rows: [], }; } const parentID = parentRows[parentRowIndex].id; - // We store row indexes to "slice out" the array rows - // that belong to each parent row - rowsByTable[tableName].rowIndexMap.push([ - rowsByTable[tableName].rows.length, rowsByTable[tableName].rows.length + arrayRows.length, - ]); - // Add any sub arrays that need to be created // We will call this recursively below - arrayRows.forEach((arrayRow, arrayRowIndex) => { + arrayRows.forEach((arrayRow) => { if (Object.keys(arrayRow.arrays).length > 0) { rowsByTable[tableName].arrays.push(arrayRow.arrays); } @@ -69,18 +52,11 @@ export const insertArrays = async ({ arrayRow.row._parentID = parentID; rowsByTable[tableName].rows.push(arrayRow.row); - const existingLocaleCount = rowsByTable[tableName].locales.length; - Object.entries(arrayRow.locales).forEach(([arrayRowLocale, arrayRowLocaleData]) => { arrayRowLocaleData._parentID = arrayRow.row.id; arrayRowLocaleData._locale = arrayRowLocale; rowsByTable[tableName].locales.push(arrayRowLocaleData); }); - - rowsByTable[tableName].localeRowIndexMap[arrayRowIndex] = [ - existingLocaleCount, - existingLocaleCount + Object.keys(arrayRow.locales).length, - ]; }); }); }); @@ -90,31 +66,15 @@ export const insertArrays = async ({ await Promise.all(Object.entries(rowsByTable).map(async ( [tableName, row], ) => { - const insertedRows = await adapter.db.insert(adapter.tables[tableName]) + await adapter.db.insert(adapter.tables[tableName]) .values(row.rows).returning(); - let insertedLocaleRows: Record[] = []; - // Insert locale rows if (adapter.tables[`${tableName}_locales`]) { - insertedLocaleRows = await adapter.db.insert(adapter.tables[`${tableName}_locales`]) + await adapter.db.insert(adapter.tables[`${tableName}_locales`]) .values(row.locales).returning(); } - rowsByTable[tableName].rows = insertedRows.map((arrayRow, i) => { - if (Array.isArray(row.localeRowIndexMap[i])) { - const sliceStart = row.localeRowIndexMap[i][0]; - const sliceEnd = row.localeRowIndexMap[i][1]; - const localeRows = insertedLocaleRows.slice(sliceStart, sliceEnd); - - if (localeRows.length > 0) { - arrayRow._locales = localeRows; - } - } - - return arrayRow; - }); - // If there are sub arrays, call this function recursively if (row.arrays.length > 0) { await insertArrays({ @@ -124,12 +84,4 @@ export const insertArrays = async ({ }); } })); - - // Finally, hoist up the newly inserted arrays to their parent row - // by slicing out the appropriate range from rowIndexMap - Object.values(rowsByTable).forEach(({ rows, columnName, rowIndexMap }) => { - rowIndexMap.forEach(([start, finish], i) => { - parentRows[i][columnName] = rows.slice(start, finish); - }); - }); }; diff --git a/test/postgres/int.spec.ts b/test/postgres/int.spec.ts index 187e4fc5f8..3b14bc5cad 100644 --- a/test/postgres/int.spec.ts +++ b/test/postgres/int.spec.ts @@ -133,7 +133,8 @@ describe('Postgres', () => { it('adds locale to existing doc', async () => { const titleES = 'hello es'; - const arrayTitle = 'hello 1 spanish'; + const arrayTitle1 = 'hello 1 spanish'; + const arrayTitle2 = 'hello 2 spanish'; const blockLocalizedText = 'my block in spanish'; const updatedPost = await payload.update({ @@ -146,7 +147,11 @@ describe('Postgres', () => { myArray: [ { id: post.myArray[0].id, - subField: arrayTitle, + subField: arrayTitle1, + }, + { + id: post.myArray[1].id, + subField: arrayTitle2, }, ], myBlocks: [ @@ -160,7 +165,8 @@ describe('Postgres', () => { expect(updatedPost.title).toStrictEqual(titleES); expect(updatedPost.number).toStrictEqual(1000); - expect(updatedPost.myArray[0].subField).toStrictEqual(arrayTitle); + expect(updatedPost.myArray[0].subField).toStrictEqual(arrayTitle1); + expect(updatedPost.myArray[1].subField).toStrictEqual(arrayTitle2); expect(updatedPost.myBlocks[0].localizedText).toStrictEqual(blockLocalizedText); }); @@ -206,6 +212,7 @@ describe('Postgres', () => { ], myArray: [ { + id: post.myArray[0].id, subField: 'hello 1 updated', mySubArray: [ { @@ -217,6 +224,7 @@ describe('Postgres', () => { ], }, { + id: post.myArray[1].id, subField: 'hello 2 updated', mySubArray: [ { @@ -230,11 +238,13 @@ describe('Postgres', () => { ], myBlocks: [ { + id: post.myBlocks[0].id, blockType: 'block1', nonLocalizedText: 'hello updated', localizedText: 'hello in english updated', }, { + id: post.myBlocks[1].id, blockType: 'block2', number: 1234, blockArray: [