References, slugs and what the platform enforces
Strong references must resolve and published slugs must be unique. Both are enforced on write and publish by the platform itself, not only by the Studio.
Most schema validation is advisory. Two rules are not, and they are enforced inside the same transaction as the write.
Strong references must resolve
A reference is strong unless it is marked weak. Publishing a document whose strong reference points at a document that does not exist is refused.
defineField({
name: 'author',
type: 'reference',
to: [{ type: 'author' }],
validation: (Rule) => Rule.required(),
})The check counts the transaction's own effects as state, which is why a seed can create a post and its author in one transaction on an empty database and have the reference hold.
The mirror image also holds: deleting a document that a strong reference points at is refused, with the referring documents named in the error.
Published slugs are unique
The uniqueness set is the published documents, per type — the same default Sanity's own slug validator uses. That definition is the one that works:
- Only published documents are routable, so only they can collide in a URL space.
- Two drafts may hold the same slug, and the second one to be published is rejected, at publish time, which is exactly when the collision becomes real.
- A draft never conflicts with its own published row, because the comparison is by published id.
Optimistic concurrency
Any mutation may carry ifRevisionID (or ifPublishedRevisionId for an action). It is compared against the stored revision, and a mismatch is a conflict rather than a silent overwrite — which is what stops two editors saving over each other.
