Skip to content

Commit 395e1ed

Browse files
authored
feat: add disableUnique property to the slug field for better multi tenant plugin support (#15963)
Fixes #14938 This PR adds a new property `disableUnique` which is useful when you want to add a compound unique index to the collection `indexes` config instead, for example with the multi-tenant plugin where the slug is only unique per tenant, not globally.
1 parent dc98f0f commit 395e1ed

2 files changed

Lines changed: 20 additions & 11 deletions

File tree

docs/fields/text.mdx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -212,16 +212,17 @@ export const ExampleCollection: CollectionConfig = {
212212

213213
The slug field exposes a few top-level config options for easy customization:
214214

215-
| Option | Description |
216-
| -------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
217-
| `name` | To be used as the slug field's name. Defaults to `slug`. |
218-
| `overrides` | A function that receives the default fields so you can override on a granular level. See example below. [More details](#slug-overrides). |
219-
| `checkboxName` | To be used as the name for the `generateSlug` checkbox field. Defaults to `generateSlug`. |
220-
| `useAsSlug` | The name of the top-level field to use when generating the slug. This field must exist in the same collection. Defaults to `title`. |
221-
| `localized` | Enable localization on the `slug` and `generateSlug` fields. Defaults to `false`. |
222-
| `position` | The position of the slug field. [More details](./overview#admin-options). |
223-
| `required` | Require the slug field. Defaults to `true`. |
224-
| `slugify` | Override the default slugify function. [More details](#custom-slugify-function). |
215+
| Option | Description |
216+
| --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
217+
| `name` | To be used as the slug field's name. Defaults to `slug`. |
218+
| `overrides` | A function that receives the default fields so you can override on a granular level. See example below. [More details](#slug-overrides). |
219+
| `checkboxName` | To be used as the name for the `generateSlug` checkbox field. Defaults to `generateSlug`. |
220+
| `disableUnique` | Disables the unique index on the field. Useful when you want to add a compound unique index to the collection `indexes` config instead, for example with the multi-tenant plugin where the slug is only unique per tenant, not globally |
221+
| `useAsSlug` | The name of the top-level field to use when generating the slug. This field must exist in the same collection. Defaults to `title`. |
222+
| `localized` | Enable localization on the `slug` and `generateSlug` fields. Defaults to `false`. |
223+
| `position` | The position of the slug field. [More details](./overview#admin-options). |
224+
| `required` | Require the slug field. Defaults to `true`. |
225+
| `slugify` | Override the default slugify function. [More details](#custom-slugify-function). |
225226

226227
### Slug Overrides
227228

packages/payload/src/fields/baseFields/slug/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ export type SlugFieldArgs = {
1717
* @default 'generateSlug'
1818
*/
1919
checkboxName?: string
20+
/**
21+
* Disables the unique index on the field.
22+
* This is useful if instead, you want to add a compound unique index to the collection `indexes` config,
23+
* for example with the multi tenant plugin, where the slug is only unique per tenant, not globally.
24+
* @default false
25+
*/
26+
disableUnique?: boolean
2027
/**
2128
* @deprecated use `useAsSlug` instead.
2229
*/
@@ -88,6 +95,7 @@ export type SlugFieldClientProps = SlugFieldClientPropsOnly & TextFieldClientPro
8895
export const slugField: SlugField = ({
8996
name: slugFieldName = 'slug',
9097
checkboxName = 'generateSlug',
98+
disableUnique = false,
9199
fieldToUse,
92100
localized,
93101
overrides,
@@ -145,7 +153,7 @@ export const slugField: SlugField = ({
145153
index: true,
146154
localized,
147155
required,
148-
unique: true,
156+
unique: !disableUnique,
149157
},
150158
],
151159
}

0 commit comments

Comments
 (0)