fix(db-postgres): localized array inside blocks field (#7457)

fixes #7371, #5240
This commit is contained in:
Dan Ribbens
2024-07-31 16:33:52 -04:00
committed by GitHub
parent 290ffd3287
commit 1ec78a16f0
3 changed files with 45 additions and 1 deletions

View File

@@ -4,8 +4,10 @@ import { fieldAffectsData, fieldHasSubFields } from 'payload/shared'
export const hasLocalesTable = (fields: Field[]): boolean => {
return fields.some((field) => {
// arrays always get a separate table
if (field.type === 'array') return false
if (fieldAffectsData(field) && field.localized) return true
if (fieldHasSubFields(field) && field.type !== 'array') return hasLocalesTable(field.fields)
if (fieldHasSubFields(field)) return hasLocalesTable(field.fields)
if (field.type === 'tabs') return field.tabs.some((tab) => hasLocalesTable(tab.fields))
return false
})

View File

@@ -184,6 +184,28 @@ const BlockFields: CollectionConfig = {
},
},
},
{
name: 'blocksWithLocalizedArray',
type: 'blocks',
blocks: [
{
slug: 'localizedArray',
fields: [
{
name: 'array',
type: 'array',
localized: true,
fields: [
{
name: 'text',
type: 'text',
},
],
},
],
},
],
},
{
name: 'blocksWithSimilarConfigs',
type: 'blocks',

View File

@@ -1278,6 +1278,26 @@ describe('Fields', () => {
expect(equalsMissResult).toBeUndefined()
expect(inMissResult).toBeUndefined()
})
it('should allow localized array of blocks', async () => {
const result = await payload.create({
collection: blockFieldsSlug,
data: {
blocksWithLocalizedArray: [
{
blockType: 'localizedArray',
array: [
{
text: 'localized',
},
],
},
],
},
})
expect(result.blocksWithLocalizedArray[0].array[0].text).toEqual('localized')
})
})
describe('json', () => {