fix(db-postgres): localized array inside blocks field (#7457)
fixes #7371, #5240
This commit is contained in:
@@ -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
|
||||
})
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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', () => {
|
||||
|
||||
Reference in New Issue
Block a user