129
Specify relation column as required
A
Ashxdev
hi, any updates here?
ІП-22мп Кемарський Микита
Any updates on it?
Marc Roig Campos
Jen Tak As you clearly explained, Strapi changed the object to work with relations.
Making required relations was working before but was not something Strapi supported.
We plan to work on this in the near future and is something we are discussing how to implement.
Jen Tak
Just wanted to add that the
required: true
option in schema.json
doesn't work since 4.5.0 where https://github.com/strapi/strapi/pull/14401/ was released.With that PR the content manager started submitting more complex object as the value for relations fields even if the value was empty. Unfortunately, this object passes through the
required
validator as it merely checks the value isn’t null or undefined.The validator will keep working in the REST API as long as the clients won't use this new object syntax. In other words, the validator works but can be circumvented by a specifically crafted request. So don't rely on it, if you positively must enforce the rule.
Jen Tak
In Strapi v4.3.9 if i add
required:true
to the field specification in schema.json
the relation seems to be enforced. The UX is a bit subpar: just flashing an error "<field> cannot be null" after trying to save. But better than nothing.Would be nice if the docs mentioned this. .)
A
AndreasP
Do we know if the strapi team will create a solution for this?
Leandro de Paula Borges
Also, be able to set a max and min validation to a relation, since there is some use cases that business need that a component can have at max N entries for a relation.
Rubén Chiquin
Perhaps this could first be implemented at a user level, and leave the enforcing at the database level for later, as @hunter mentioned in his workaround in https://forum.strapi.io/t/required-relation-field/624/3
This could mean a very low-cost implementation and would save us from the typicial error of leaving those columns unfilled and creating a 500 error on the frontEnd.
dzcpy
Also, better support cascade delete when a required relation entry is deleted