Skip to content

Commit

Permalink
fix: #2711 index sortable field global versions fields (#2775)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanRibbens committed Jun 6, 2023
1 parent 8b767a1 commit 576af01
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/globals/initLocal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default function initGlobalsLocal(ctx: Payload): void {
ctx.config,
versionGlobalFields,
{
indexSortableFields: ctx.config.indexSortableFields,
disableUnique: true,
draftsEnabled: true,
options: {
Expand Down
10 changes: 8 additions & 2 deletions src/mongoose/buildSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import {
EmailField,
Field,
FieldAffectingData,
fieldAffectsData, fieldIsLocalized,
fieldAffectsData,
fieldIsLocalized,
fieldIsPresentationalOnly,
GroupField,
JSONField,
Expand All @@ -31,7 +32,8 @@ import {
tabHasName,
TabsField,
TextareaField,
TextField, UnnamedTab,
TextField,
UnnamedTab,
UploadField,
} from '../fields/config/types';

Expand Down Expand Up @@ -384,6 +386,9 @@ const fieldToSchemaMap: Record<string, FieldSchemaGenerator> = {
group: (field: GroupField, schema: Schema, config: SanitizedConfig, buildSchemaOptions: BuildSchemaOptions): void => {
const formattedBaseSchema = formatBaseSchema(field, buildSchemaOptions);

// carry indexSortableFields through to versions if drafts enabled
const indexSortableFields = (buildSchemaOptions.indexSortableFields && field.name === 'version' && buildSchemaOptions.draftsEnabled);

const baseSchema = {
...formattedBaseSchema,
type: buildSchema(
Expand All @@ -395,6 +400,7 @@ const fieldToSchemaMap: Record<string, FieldSchemaGenerator> = {
id: false,
minimize: false,
},
indexSortableFields,
disableUnique: buildSchemaOptions.disableUnique,
draftsEnabled: buildSchemaOptions.draftsEnabled,
},
Expand Down
1 change: 1 addition & 0 deletions test/versions/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default buildConfig({
locales: ['en', 'es'],
defaultLocale: 'en',
},
indexSortableFields: true,
onInit: async (payload) => {
await payload.create({
collection: 'users',
Expand Down

0 comments on commit 576af01

Please sign in to comment.