Fix/propagate locale relationship (#637)
* fix: propagate locale through relationship * fix: ensures locales are populated properly through local operations * chore: adds test for locale propagation Co-authored-by: Elliot DeNolf <denolfe@gmail.com>
This commit is contained in:
@@ -22,8 +22,8 @@ export default async function create<T = any>(options: Options<T>): Promise<T> {
|
||||
const {
|
||||
collection: collectionSlug,
|
||||
depth,
|
||||
locale = this?.config?.localization?.defaultLocale,
|
||||
fallbackLocale = null,
|
||||
locale,
|
||||
fallbackLocale,
|
||||
data,
|
||||
user,
|
||||
overrideAccess = true,
|
||||
@@ -47,11 +47,11 @@ export default async function create<T = any>(options: Options<T>): Promise<T> {
|
||||
overwriteExistingFiles,
|
||||
draft,
|
||||
req: {
|
||||
...req,
|
||||
...req || {},
|
||||
user,
|
||||
payloadAPI: 'local',
|
||||
locale,
|
||||
fallbackLocale,
|
||||
locale: locale || req?.locale || this?.config?.localization?.defaultLocale,
|
||||
fallbackLocale: fallbackLocale || req?.fallbackLocale || null,
|
||||
payload: this,
|
||||
files: {
|
||||
file: getFileByPath(filePath),
|
||||
|
||||
@@ -35,8 +35,8 @@ export default async function localDelete<T extends TypeWithID = any>(options: O
|
||||
req: {
|
||||
user,
|
||||
payloadAPI: 'local',
|
||||
locale,
|
||||
fallbackLocale,
|
||||
locale: locale || this?.config?.localization?.defaultLocale,
|
||||
fallbackLocale: fallbackLocale || null,
|
||||
payload: this,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -23,13 +23,13 @@ export default async function findByID<T extends TypeWithID = any>(options: Opti
|
||||
depth,
|
||||
currentDepth,
|
||||
id,
|
||||
locale = this?.config?.localization?.defaultLocale,
|
||||
fallbackLocale = null,
|
||||
locale,
|
||||
fallbackLocale,
|
||||
user,
|
||||
overrideAccess = true,
|
||||
disableErrors = false,
|
||||
showHiddenFields,
|
||||
req = {},
|
||||
req,
|
||||
draft = false,
|
||||
} = options;
|
||||
|
||||
@@ -39,8 +39,8 @@ export default async function findByID<T extends TypeWithID = any>(options: Opti
|
||||
user: undefined,
|
||||
...req || {},
|
||||
payloadAPI: 'local',
|
||||
locale,
|
||||
fallbackLocale,
|
||||
locale: locale || req?.locale || this?.config?.localization?.defaultLocale,
|
||||
fallbackLocale: fallbackLocale || req?.fallbackLocale || null,
|
||||
payload: this,
|
||||
};
|
||||
|
||||
|
||||
@@ -38,10 +38,10 @@ export default async function findVersionByID<T extends TypeWithVersion<T> = any
|
||||
disableErrors,
|
||||
showHiddenFields,
|
||||
req: {
|
||||
...req,
|
||||
...req || {},
|
||||
payloadAPI: 'local',
|
||||
locale,
|
||||
fallbackLocale,
|
||||
locale: locale || req?.locale || this?.config?.localization?.defaultLocale,
|
||||
fallbackLocale: fallbackLocale || req?.fallbackLocale || null,
|
||||
payload: this,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -10,6 +10,7 @@ let token = null;
|
||||
let headers = null;
|
||||
|
||||
let localizedPostID;
|
||||
let relationshipBID;
|
||||
const localizedPostTitle = 'title';
|
||||
const englishPostDesc = 'english description';
|
||||
const spanishPostDesc = 'spanish description';
|
||||
@@ -503,6 +504,7 @@ describe('Collections - REST', () => {
|
||||
}).then((res) => res.json());
|
||||
|
||||
expect(relationshipB.doc.id).toBeDefined();
|
||||
relationshipBID = relationshipB.doc.id;
|
||||
|
||||
const queryRes = await fetch(
|
||||
`${url}/api/relationship-b?where[nonLocalizedRelationToMany.value][equals]=${localizedPostID}`,
|
||||
@@ -511,6 +513,15 @@ describe('Collections - REST', () => {
|
||||
expect(data.docs).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('should propagate locale through populated documents', async () => {
|
||||
const relationshipB = await fetch(`${url}/api/relationship-b/${relationshipBID}?locale=es`, {
|
||||
headers,
|
||||
});
|
||||
|
||||
const data = await relationshipB.json();
|
||||
expect(data.nonLocalizedRelationToMany.value.description).toBe(spanishPostDesc);
|
||||
});
|
||||
|
||||
it('should allow querying by a numeric custom ID', async () => {
|
||||
const customID = 1988;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user