Welcome Guest, Not a member yet? Register   Sign In
More flexible validationRules in model?
#2

(This post was last modified: 02-27-2020, 07:40 AM by zahhar.)

This is a very valid architecture point, michalsn.

I would fully support getters/setters for (almost) all protected attributes, like $validationRules or $allowedFields. Moreover, it is very easy to implement and suggest to include into subsequent releases of CI4.

When it comes to separation of validation logic and and list of allowed fields for create/update actions, I like the approach RubyOnRails uses in its ActiveRecord:

1. You can define generic validation rules applicable in any case, and on top of that customize them for create/update actions. Totally makes sense: https://guides.rubyonrails.org/active_re...ns.html#on

2. For $allowedFields differenciation on updated/create it offers slightly different approach: Model is allowed to have readonly attributes. Those attributes will be set only when record is created using $myModel->insert(), but ignored during $myModel->update() call. It would be cool to have $readonlyFields introduced in CI4.x.

I am also happy to work on pull request.
Reply


Messages In This Thread
RE: More flexible validationRules in model? - by zahhar - 02-27-2020, 07:39 AM



Theme © iAndrew 2016 - Forum software by © MyBB