Merge pull request #2206 from payloadcms/fix/2189-empty-json
fix: allows empty objects to be retained in db
This commit is contained in:
@@ -11,7 +11,11 @@ const buildCollectionSchema = (collection: SanitizedCollectionConfig, config: Sa
|
||||
collection.fields,
|
||||
{
|
||||
draftsEnabled: Boolean(typeof collection?.versions === 'object' && collection.versions.drafts),
|
||||
options: { timestamps: collection.timestamps !== false, ...schemaOptions },
|
||||
options: {
|
||||
timestamps: collection.timestamps !== false,
|
||||
minimize: false,
|
||||
...schemaOptions,
|
||||
},
|
||||
indexSortableFields: config.indexSortableFields,
|
||||
},
|
||||
);
|
||||
|
||||
@@ -70,6 +70,7 @@ export default function initCollectionsLocal(ctx: Payload): void {
|
||||
draftsEnabled: true,
|
||||
options: {
|
||||
timestamps: false,
|
||||
minimize: false,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
@@ -6,14 +6,22 @@ import { GlobalModel } from './config/types';
|
||||
|
||||
const buildModel = (config: SanitizedConfig): GlobalModel | null => {
|
||||
if (config.globals && config.globals.length > 0) {
|
||||
const globalsSchema = new mongoose.Schema({}, { discriminatorKey: 'globalType', timestamps: true });
|
||||
const globalsSchema = new mongoose.Schema({}, { discriminatorKey: 'globalType', timestamps: true, minimize: false });
|
||||
|
||||
globalsSchema.plugin(buildQueryPlugin);
|
||||
|
||||
const Globals = mongoose.model('globals', globalsSchema) as unknown as GlobalModel;
|
||||
|
||||
Object.values(config.globals).forEach((globalConfig) => {
|
||||
const globalSchema = buildSchema(config, globalConfig.fields, { global: true });
|
||||
const globalSchema = buildSchema(
|
||||
config,
|
||||
globalConfig.fields,
|
||||
{
|
||||
options: {
|
||||
minimize: false,
|
||||
},
|
||||
},
|
||||
);
|
||||
Globals.discriminator(globalConfig.slug, globalSchema);
|
||||
});
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ export default function initGlobalsLocal(ctx: Payload): void {
|
||||
draftsEnabled: true,
|
||||
options: {
|
||||
timestamps: false,
|
||||
minimize: false,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
@@ -40,7 +40,6 @@ export type BuildSchemaOptions = {
|
||||
allowIDField?: boolean
|
||||
disableUnique?: boolean
|
||||
draftsEnabled?: boolean
|
||||
global?: boolean
|
||||
indexSortableFields?: boolean
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user