Specify relation column as required
complete

Emilie Ringwald
Merged in a post:
Can not make relation field 'required'
R
Risini Piyathma
Strapi v4
I have a collection type named 'Home'.
In the dynamic zone of Home, there is a component, and inside of that component, there is a field with relation. I want to make that relation field required.
Tried this with lifecycle hooks. But component data inside of dynamic zone can not be read within lifecycle.
Any solution for this, or Can make feature changes ?

Emilie Ringwald
Merged in a post:
Relation field make it required
v
vitali
Relation field required TRUE or FALSE

Strapi Team
updated the status to
complete

Emilie Ringwald
Hey everyone, thanks for flagging this and for your patience, this has been one of our most requested relations fixes for a while.
Required relations are officially supported as of Strapi 5.51.2 (the enforcement landed in 5.51.1, the Content-Type Builder toggle followed right after in 5.51.2).
What changed: you can now check "Required" on a relation field in the Content-Type Builder, just like you would for any other field, and Strapi will actually block publishing an entry if that relation is empty. Drafts stay flexible, the check only kicks in when you hit publish.
One important thing to know: brand new projects get this enforcement turned on automatically. If you're on an existing project, you'll need to turn it on yourself by setting documents.strictRelations: true in your config/api.js. We made it opt-in for existing projects so we don't silently break anything currently relying on the old behavior.
Marking this as shipped. Let us know if you run into anything unexpected!
sc tester
Now, with conditional fields, we could almost build a button component which supports different "links". A text field with regex pattern to allow plain URLs and different relation fields to dynamically link to content inside of Strapi.
(And a field to select which link field is shown)
But as long as we can't make the relation fields required, it will happen that our content editors accidentally publish pages with "empty" (broken) links.
Nguyen Huu Kim
If you are using Strapi 5, you can try this one:
Nguyen Huu Kim
If you are using Strapi 5, you can try this one:
Bhavya Bhut
Any update?
B
Benjamin Schneider
how is it possible that this is still open after 6 years?!
KP
hi, any updates for making relationship field required?
Load More
→