fix(drizzle): array/relationship/select hasMany in localized field (#8355)

This PR addresses these issues with localized groups / tabs with
Postgres / SQLite:

- Array fields inside of localized groups. Fixes
https://github.com/payloadcms/payload/issues/8322
- Select fields with `hasMany: true` inside of localized groups. Related
to 1, but still needed its own additional logic.
- Relationship (non-polymorphic / non has-many) inside of localized
groups. Previously, even just trying to define them in the config led to
a crash. Fixes https://github.com/payloadcms/payload/issues/8308

Ensures test coverage for localized groups.
This commit is contained in:
Sasha
2024-09-23 18:34:02 +03:00
committed by GitHub
parent 36ba6d47b4
commit 338c93a229
6 changed files with 192 additions and 3 deletions

View File

@@ -879,7 +879,7 @@ export const traverseFields = ({
// add relationship to table
relationsToBuild.set(fieldName, {
type: 'one',
localized: adapter.payload.config.localization && field.localized,
localized: adapter.payload.config.localization && (field.localized || forceLocalized),
target: tableName,
})

View File

@@ -886,7 +886,7 @@ export const traverseFields = ({
// add relationship to table
relationsToBuild.set(fieldName, {
type: 'one',
localized: adapter.payload.config.localization && field.localized,
localized: adapter.payload.config.localization && (field.localized || forceLocalized),
target: tableName,
})

View File

@@ -527,13 +527,23 @@ export const traverseFields = <T extends Record<string, unknown>>({
return selectResult
}, {})
} else {
result[field.name] = fieldData.map(({ value }) => value)
let selectData = fieldData
if (withinArrayOrBlockLocale) {
selectData = selectData.filter(({ locale }) => locale === withinArrayOrBlockLocale)
}
result[field.name] = selectData.map(({ value }) => value)
}
}
return result
}
if (field.localized && Array.isArray(table._locales)) {
if (!table._locales.length && adapter.payload.config.localization) {
adapter.payload.config.localization.localeCodes.forEach((_locale) =>
(table._locales as unknown[]).push({ _locale }),
)
}
table._locales.forEach((localeRow) => {
valuesToTransform.push({
ref: localizedFieldData,