Is a unique field globally unique or locale unique?

System Information
  • Strapi Version: 3

I’ve seen this mentioned a few times but there doesn’t seem to be a well documented answer so I’m asking again.

We have a situation where we have a content type with a slug field. The content type can be localised and in some cases, the slug will be the same in more than one locale version of a page.

Ideally, we would like to be able to publish a new page with the same slug if it’s in a different locale and restrict publishing if it’s in the same one.

Is this possible? As far as i can see from local dev, adding a unique constraint to the slug adds a unique constraint to the DB table which prevents the above behaviour.

beforeCreate & beforeUpdate of your page you could perform a findOne on page with {slugAttribute: slugAttribute, _locale: localeThatYouAreAboutToSafe}.

Atleast that’s how I do it (in v3).

Yep that’s what we are doing.

My original question was about locking the ability to add an entry with the same slug for the same locale. We want to make sure our translators can’t make a mistake.