Welcome Guest, Not a member yet? Register   Sign In
Model validation vs validationService and required field
#1

Hello. 
I would like to get some précisions with the Model validation functions in CI4 
I’m experimenting a difference of comportement between Services::validation() and the validation of the Model object for the required rule. 
With Services::validation(), a required field will be checked and fail if the parameter is set and null or is not set.
With the validation function of the Model object, a required field will be checked only if the parameter is set. So, the rule will fail if the parameter is set and null. But if the parameter is not set, the validation rule will not fail. 
I haven’t found any data about this difference of comportment in the CI documentation. It may be interesting to have some words about that because this can be confusing. 
As I understand, validation in the Model ignore unseted fields to allow partials modifications of a database record. It make sense. But on another side a required field is a required field. It’s confusing that a required field rule is ignored in an update method. Maybe the update method should have a third parameter allowing partial rules check (unseted fields will be ignored) or full rule check (all rules will apply and unseted fields marked as required will raise an error) ?
Reply


Messages In This Thread
Model validation vs validationService and required field - by Tomv13 - 08-26-2022, 02:58 PM



Theme © iAndrew 2016 - Forum software by © MyBB