fix: field paths being mutated if they ended with the req.locale (#3936)
This commit is contained in:
@@ -104,7 +104,7 @@ export async function validateSearchParam({
|
||||
let fieldAccess
|
||||
let fieldPath = path
|
||||
// remove locale from end of path
|
||||
if (path.endsWith(req.locale)) {
|
||||
if (path.endsWith(`.${req.locale}`)) {
|
||||
fieldPath = path.slice(0, -(req.locale.length + 1))
|
||||
}
|
||||
// remove ".value" from ends of polymorphic relationship paths
|
||||
|
||||
@@ -88,6 +88,22 @@ export default buildConfigWithDefaults({
|
||||
type: 'checkbox',
|
||||
localized: true,
|
||||
},
|
||||
{
|
||||
name: 'children',
|
||||
type: 'relationship',
|
||||
relationTo: localizedPostsSlug,
|
||||
hasMany: true,
|
||||
},
|
||||
{
|
||||
type: 'group',
|
||||
name: 'group',
|
||||
fields: [
|
||||
{
|
||||
name: 'children',
|
||||
type: 'text',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
ArrayCollection,
|
||||
|
||||
@@ -5,7 +5,9 @@ import type { Where } from '../../packages/payload/src/types'
|
||||
import type { LocalizedPost, WithLocalizedRelationship } from './payload-types'
|
||||
|
||||
import payload from '../../packages/payload/src'
|
||||
import { devUser } from '../credentials'
|
||||
import { initPayloadTest } from '../helpers/configHelpers'
|
||||
import { RESTClient } from '../helpers/rest'
|
||||
import { arrayCollectionSlug } from './collections/Array'
|
||||
import configPromise from './config'
|
||||
import {
|
||||
@@ -25,6 +27,7 @@ import {
|
||||
|
||||
const collection = localizedPostsSlug
|
||||
let config: Config
|
||||
let client: RESTClient
|
||||
|
||||
let serverURL
|
||||
|
||||
@@ -34,6 +37,15 @@ describe('Localization', () => {
|
||||
|
||||
beforeAll(async () => {
|
||||
;({ serverURL } = await initPayloadTest({ __dirname, init: { local: false } }))
|
||||
client = new RESTClient(config, { serverURL, defaultSlug: collection })
|
||||
await client.create({
|
||||
data: {
|
||||
email: devUser.email,
|
||||
password: devUser.password,
|
||||
},
|
||||
})
|
||||
await client.login()
|
||||
|
||||
config = await configPromise
|
||||
|
||||
// @ts-expect-error Force typing
|
||||
@@ -68,7 +80,7 @@ describe('Localization', () => {
|
||||
}
|
||||
})
|
||||
|
||||
describe('localized text', () => {
|
||||
describe('Localized text', () => {
|
||||
it('create english', async () => {
|
||||
const allDocs = await payload.find({
|
||||
collection,
|
||||
@@ -756,6 +768,43 @@ describe('Localization', () => {
|
||||
expect(updatedSpanishDoc.items[0].text).toStrictEqual(englishTitle)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Localized - Field Paths', () => {
|
||||
it('should allow querying by non-localized field names ending in a locale', async () => {
|
||||
await payload.update({
|
||||
collection,
|
||||
id: post1.id,
|
||||
data: {
|
||||
children: post1.id,
|
||||
group: {
|
||||
children: 'something',
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
const { result: relationshipRes } = await client.find({
|
||||
auth: true,
|
||||
query: {
|
||||
children: {
|
||||
in: post1.id,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
expect(relationshipRes.docs.map(({ id }) => id)).toContain(post1.id)
|
||||
|
||||
const { result: nestedFieldRes } = await client.find({
|
||||
auth: true,
|
||||
query: {
|
||||
'group.children': {
|
||||
contains: 'some',
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
expect(nestedFieldRes.docs.map(({ id }) => id)).toContain(post1.id)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
async function createLocalizedPost(data: {
|
||||
|
||||
Reference in New Issue
Block a user