Replies: 4 comments 5 replies
-
This is be fixed as of v1.0.12 via #867 |
Beta Was this translation helpful? Give feedback.
-
Not sure if it is an isolated issue, but I'm still facing the same problem. I regenerated the whole DB and nothing changed. Also, it seems like an index was not created. Payload: v1.0.19 name: 'metaUrlSlug',
label: 'URL Slug',
type: 'text',
required: true, // Show red * in the field, but its validation is overridden by "validate"
unique: true,
index: true,
validate: async (value, { operation }) => {
if (operation === 'create' || operation === 'update') {
// Value is undefined during admin UI navigation
// This crashes the validation process and causes unexpected behavior
// Turn value into an empty string instead as a workaround
value = value ?? '';
const re = /^[a-z0-9-]+$/;
return value.match(re)
? true
: 'URL slug must contain only lower case characters from a to z, 0 to 9, or hyphen.';
}
}, |
Beta Was this translation helpful? Give feedback.
-
Having the same issue here. Collection config: const Users: CollectionConfig = {
slug: "users",
auth: true,
fields: [
{
name: "name",
type: "text",
unique: true,
required: true
},
// ...
],
// ...
}; Performing the following requests in my Jest test: const resFirst = await request(app).post(`/api/${Users.slug}/`).set("Authorization", `JWT ${loginToken}`).send({ ...regularUser, email: "[email protected]" });
expect(resFirst.statusCode).toBe(201);
console.log(resFirst.body);
const resSecond = await request(app).post(`/api/${Users.slug}/`).set("Authorization", `JWT ${loginToken}`).send({ ...regularUser, email: "[email protected]" });
console.log(resSecond.body);
expect(resSecond.statusCode).toBe(400); // fails here because status code is 201 Results of the
As you can see, two users with the exact same name are created, even though, there is a Running on latest |
Beta Was this translation helpful? Give feedback.
-
@DanRibbens After further testing, it seems like Fields cannot be unique or indexed when residing in a import { CollectionConfig } from 'payload/types';
const Test: CollectionConfig = {
slug: 'test',
fields: [
{
name: 'neitherInCollapsibleNorGroup',
label: 'Neither in Collapsible nor Group',
type: 'text',
unique: true
},
{
label: 'Collapsible - visual only',
type: 'collapsible',
fields: [
{
name: 'inCollapsible',
label: 'In Collapsible',
type: 'text',
unique: true,
},
],
},
{
name: 'group',
label: 'Group - both visual and in DB structure',
type: 'group',
fields: [
{
name: 'inGroup',
label: 'In Group',
type: 'text',
unique: true,
},
],
},
],
timestamps: true,
versions: {
drafts: true,
},
};
export default Test; Result: |
Beta Was this translation helpful? Give feedback.
-
Hello! Thanks again for maintaining payloadcms @jmikrut
When creating a new user via a REST API call, I tested creating a user with a duplicate 'username'. I've marked this field as unique in the field setup, but it allowed me to create the additional user. Am I setting the field unique property incorrectly?
Thank you!
Chris

Example of fetch request:
Beta Was this translation helpful? Give feedback.
All reactions