fix: ensures non-localized relationships with many relationTos can be queried

This commit is contained in:
James
2021-11-24 18:01:33 -05:00
parent 38ee73ba2e
commit 7050b5285e
3 changed files with 39 additions and 2 deletions

View File

@@ -432,7 +432,7 @@ describe('Collections - REST', () => {
expect(data1.docs).toHaveLength(1);
});
it('should allow querying by a localized nested relationship property with many relationTos', async () => {
it('should allow querying by a localized nested relationship with many relationTos', async () => {
const relationshipBTitle = 'lawleifjawelifjew';
const relationshipB = await fetch(`${url}/api/relationship-b?depth=0`, {
body: JSON.stringify({
@@ -462,6 +462,26 @@ describe('Collections - REST', () => {
expect(data.docs).toHaveLength(1);
});
it('should allow querying by a non-localized relationship with many relationTos', async () => {
const relationshipB = await fetch(`${url}/api/relationship-b?depth=0`, {
body: JSON.stringify({
title: 'awefjlaiwejfalweiijfaew',
nonLocalizedRelationToMany: {
relationTo: 'localized-posts',
value: localizedPostID,
},
}),
headers,
method: 'post',
}).then((res) => res.json());
expect(relationshipB.doc.id).toBeDefined();
const queryRes = await fetch(`${url}/api/relationship-b?where[nonLocalizedRelationToMany.value][equals]=${localizedPostID}`);
const data = await queryRes.json();
expect(data.docs).toHaveLength(1);
});
it('should allow querying by a numeric custom ID', async () => {
const customID = 1988;

View File

@@ -150,6 +150,8 @@ class ParamParser {
const currentSchemaType = schema.path(currentPath);
const currentSchemaPathType = schema.pathType(currentPath);
const upcomingSegment = pathSegments[i + 1];
if (currentSchemaType && currentSchemaPathType !== 'adhocOrUndefined') {
const currentSchemaTypeOptions = getSchemaTypeOptions(currentSchemaType);
@@ -162,7 +164,6 @@ class ParamParser {
return;
}
const upcomingSegment = pathSegments[i + 1];
const upcomingPathWithLocale = `${currentPath}.${this.locale}.${upcomingSegment}`;
const upcomingSchemaTypeWithLocale = schema.path(upcomingPathWithLocale);
@@ -195,6 +196,17 @@ class ParamParser {
}
}
const upcomingPath = `${currentPath}.${upcomingSegment}`;
const upcomingSchemaType = schema.path(upcomingPath);
if (upcomingSchemaType) {
lastIncompletePath.path = upcomingPath;
lastIncompletePath.complete = true;
// Remove the next segment as it has been used here
pathSegments.splice(i + 1, 1);
return;
}
if (operator === 'near') {
lastIncompletePath.path = currentPath;
}