From acfe263dc729a3ecd5dde600d84566f12926a506 Mon Sep 17 00:00:00 2001 From: Alessio Gravili Date: Fri, 16 Jun 2023 16:07:45 +0200 Subject: [PATCH 1/4] remove auto slug pluralization --- src/collections/initLocal.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/collections/initLocal.ts b/src/collections/initLocal.ts index cc65fb66f71..67c19603895 100644 --- a/src/collections/initLocal.ts +++ b/src/collections/initLocal.ts @@ -56,7 +56,7 @@ export default function initCollectionsLocal(ctx: Payload): void { ctx.collections[formattedCollection.slug] = { - Model: mongoose.model(formattedCollection.slug, schema) as CollectionModel, + Model: mongoose.model(formattedCollection.slug, schema, formattedCollection.slug) as CollectionModel, config: formattedCollection, }; From 97e299fb39ab52d0888e3012a77dd36c1a3c55ff Mon Sep 17 00:00:00 2001 From: Alessio Gravili Date: Fri, 16 Jun 2023 16:52:47 +0200 Subject: [PATCH 2/4] feat: make slug pluralization configurable --- src/collections/initLocal.ts | 2 +- src/config/schema.ts | 1 + src/config/types.ts | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/collections/initLocal.ts b/src/collections/initLocal.ts index 67c19603895..29721f26f64 100644 --- a/src/collections/initLocal.ts +++ b/src/collections/initLocal.ts @@ -56,7 +56,7 @@ export default function initCollectionsLocal(ctx: Payload): void { ctx.collections[formattedCollection.slug] = { - Model: mongoose.model(formattedCollection.slug, schema, formattedCollection.slug) as CollectionModel, + Model: mongoose.model(formattedCollection.slug, schema, ctx.config.pluralizeSlugs === false ? formattedCollection.slug : undefined) as CollectionModel, config: formattedCollection, }; diff --git a/src/config/schema.ts b/src/config/schema.ts index 33a3ccef057..e988f869660 100644 --- a/src/config/schema.ts +++ b/src/config/schema.ts @@ -164,4 +164,5 @@ export default joi.object({ onInit: joi.func(), debug: joi.boolean(), custom: joi.object().pattern(joi.string(), joi.any()), + pluralizeSlugs: joi.boolean().optional().default(true), }); diff --git a/src/config/types.ts b/src/config/types.ts index 0720666988c..9e3cbb7e6e9 100644 --- a/src/config/types.ts +++ b/src/config/types.ts @@ -530,6 +530,12 @@ export type Config = { onInit?: (payload: Payload) => Promise | void; /** Extension point to add your custom data. */ custom?: Record; + /** + * By default, mongoose will pluralize all singular slugs so that they are saved as plural in the database. + * + * @default true + */ + pluralizeSlugs?: boolean; }; export type SanitizedConfig = Omit< From 41be0276c276297ca2d30ef984bc26ceaf6943e1 Mon Sep 17 00:00:00 2001 From: Alessio Gravili Date: Fri, 16 Jun 2023 22:01:05 +0200 Subject: [PATCH 3/4] add docs --- docs/configuration/overview.mdx | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/configuration/overview.mdx b/docs/configuration/overview.mdx index 0c7db48dcaf..2766c953b56 100644 --- a/docs/configuration/overview.mdx +++ b/docs/configuration/overview.mdx @@ -44,6 +44,7 @@ Payload is a _config-based_, code-first CMS and application framework. The Paylo | `plugins` | An array of Payload plugins. [More](/docs/plugins/overview) | | `endpoints` | An array of custom API endpoints added to the Payload router. [More](/docs/rest-api/overview#custom-endpoints) | | `custom` | Extension point for adding custom data (e.g. for plugins) | +| `pluralizeSlugs` | By default, mongoose will pluralize all singular slugs so that they are saved as plural in the database (e.g. if your slug is `post`, it will be saved as `posts`in the database.) | #### Simple example From e86ae092269f5bff998f8a8bef604fe0f35ecc76 Mon Sep 17 00:00:00 2001 From: Alessio Gravili Date: Fri, 16 Jun 2023 22:10:00 +0200 Subject: [PATCH 4/4] fix: docs table formatting --- docs/configuration/overview.mdx | 52 ++++++++++++++++----------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/docs/configuration/overview.mdx b/docs/configuration/overview.mdx index 2766c953b56..04d37f9a636 100644 --- a/docs/configuration/overview.mdx +++ b/docs/configuration/overview.mdx @@ -19,32 +19,32 @@ Payload is a _config-based_, code-first CMS and application framework. The Paylo ## Options -| Option | Description | -| --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `serverURL` | A string used to define the absolute URL of your app including the protocol, for example `https://example.com`. No paths allowed, only protocol, domain and (optionally) port | -| `collections` | An array of all Collections that Payload will manage. To read more about how to define your collection configs, [click here](/docs/configuration/collections). | -| `cors` | Either a whitelist array of URLS to allow CORS requests from, or a wildcard string (`'*'`) to accept incoming requests from any domain. | -| `globals` | An array of all Globals that Payload will manage. For more on Globals and their configs, [click here](/docs/configuration/globals). | -| `admin` | Base Payload admin configuration. Specify custom components, control metadata, set the Admin user collection, and [more](/docs/admin/overview#admin-options). | -| `localization` | Opt-in and control how Payload handles the translation of your content into multiple locales. [More](/docs/configuration/localization) | -| `graphQL` | Manage GraphQL-specific functionality here. Define your own queries and mutations, manage query complexity limits, and [more](/docs/graphql/overview#graphql-options). | -| `cookiePrefix` | A string that will be prefixed to all cookies that Payload sets. | -| `csrf` | A whitelist array of URLs to allow Payload cookies to be accepted from as a form of CSRF protection. [More](/docs/authentication/overview#csrf-protection) | -| `defaultDepth` | If a user does not specify `depth` while requesting a resource, this depth will be used. [More](/docs/getting-started/concepts#depth) | -| `maxDepth` | The maximum allowed depth to be permitted application-wide. This setting helps prevent against malicious queries. Defaults to `10`. | -| `indexSortableFields` | Automatically index all sortable top-level fields in the database to improve sort performance and add database compatibility for Azure Cosmos and similar. | -| `upload` | Base Payload upload configuration. [More](/docs/upload/overview#payload-wide-upload-options). | -| `routes` | Control the routing structure that Payload binds itself to. Specify `admin`, `api`, `graphQL`, and `graphQLPlayground`. | -| `email` | Base email settings to allow Payload to generate email such as Forgot Password requests and other requirements. [More](/docs/email/overview#configuration) | -| `express` | Express-specific middleware options such as compression and JSON parsing. [More](/docs/configuration/express) | -| `debug` | Enable to expose more detailed error information. | -| `telemetry` | Disable Payload telemetry by passing `false`. [More](/docs/configuration/overview#telemetry) | -| `rateLimit` | Control IP-based rate limiting for all Payload resources. Used to prevent DDoS attacks and [more](/docs/production/preventing-abuse#rate-limiting-requests). | -| `hooks` | Tap into Payload-wide hooks. [More](/docs/hooks/overview) | -| `plugins` | An array of Payload plugins. [More](/docs/plugins/overview) | -| `endpoints` | An array of custom API endpoints added to the Payload router. [More](/docs/rest-api/overview#custom-endpoints) | -| `custom` | Extension point for adding custom data (e.g. for plugins) | -| `pluralizeSlugs` | By default, mongoose will pluralize all singular slugs so that they are saved as plural in the database (e.g. if your slug is `post`, it will be saved as `posts`in the database.) | +| Option | Description | +| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| `serverURL` | A string used to define the absolute URL of your app including the protocol, for example `https://example.com`. No paths allowed, only protocol, domain and (optionally) port | +| `collections` | An array of all Collections that Payload will manage. To read more about how to define your collection configs, [click here](/docs/configuration/collections). | +| `cors` | Either a whitelist array of URLS to allow CORS requests from, or a wildcard string (`'*'`) to accept incoming requests from any domain. | +| `globals` | An array of all Globals that Payload will manage. For more on Globals and their configs, [click here](/docs/configuration/globals). | +| `admin` | Base Payload admin configuration. Specify custom components, control metadata, set the Admin user collection, and [more](/docs/admin/overview#admin-options). | +| `localization` | Opt-in and control how Payload handles the translation of your content into multiple locales. [More](/docs/configuration/localization) | +| `graphQL` | Manage GraphQL-specific functionality here. Define your own queries and mutations, manage query complexity limits, and [more](/docs/graphql/overview#graphql-options). | +| `cookiePrefix` | A string that will be prefixed to all cookies that Payload sets. | +| `csrf` | A whitelist array of URLs to allow Payload cookies to be accepted from as a form of CSRF protection. [More](/docs/authentication/overview#csrf-protection) | +| `defaultDepth` | If a user does not specify `depth` while requesting a resource, this depth will be used. [More](/docs/getting-started/concepts#depth) | +| `maxDepth` | The maximum allowed depth to be permitted application-wide. This setting helps prevent against malicious queries. Defaults to `10`. | +| `indexSortableFields` | Automatically index all sortable top-level fields in the database to improve sort performance and add database compatibility for Azure Cosmos and similar. | +| `upload` | Base Payload upload configuration. [More](/docs/upload/overview#payload-wide-upload-options). | +| `routes` | Control the routing structure that Payload binds itself to. Specify `admin`, `api`, `graphQL`, and `graphQLPlayground`. | +| `email` | Base email settings to allow Payload to generate email such as Forgot Password requests and other requirements. [More](/docs/email/overview#configuration) | +| `express` | Express-specific middleware options such as compression and JSON parsing. [More](/docs/configuration/express) | +| `debug` | Enable to expose more detailed error information. | +| `telemetry` | Disable Payload telemetry by passing `false`. [More](/docs/configuration/overview#telemetry) | +| `rateLimit` | Control IP-based rate limiting for all Payload resources. Used to prevent DDoS attacks and [more](/docs/production/preventing-abuse#rate-limiting-requests). | +| `hooks` | Tap into Payload-wide hooks. [More](/docs/hooks/overview) | +| `plugins` | An array of Payload plugins. [More](/docs/plugins/overview) | +| `endpoints` | An array of custom API endpoints added to the Payload router. [More](/docs/rest-api/overview#custom-endpoints) | +| `custom` | Extension point for adding custom data (e.g. for plugins) | +| `pluralizeSlugs` | By default, mongoose will pluralize all singular slugs so that they are saved as plural in the database (e.g. if your slug is `post`, it will be saved as `posts`in the database.) | #### Simple example