SofDelete and validation is_unique |
I have validation in my project: is_unique [parameters.variable, id, {id}]
PHP Code: <?php I use sof delete, when performing the registration it is validating considering the deleted records. How can I ignore deleted items (deleted_at == null) in the is_unique validation in my project? Thanks
In the current CI4 implementation all Validations include soft deleted records. Means: they are NOT ignored, but taken into consideration during evaluation of given validation criteria. So you have 4 options:
1) either permanently delete all soft deleted records before applying built-in is_unique validator, or 2) write your custom validator that will ignore soft deleted records when checking for uniqueness, 3) raise a feature request to have a setting whether soft deleted records should be included or excluded during validations (obviously, is_unique and is_not_unique should behave the same), and then wait till it gets approved, implemented and including into upcomming release, or 4) extend built-in validator and propose your change to be included into next version of CI4
(02-24-2020, 03:12 PM)zahhar Wrote: In the current CI4 implementation all Validations include soft deleted records. Means: they are NOT ignored, but taken into consideration during evaluation of given validation criteria. So you have 4 options:Hello zahhar, thank you very much. I made the following change to the is_unique validation to solve my problem: PHP Code: public function is_unique(string $str = null, string $field, array $data): bool |
Welcome Guest, Not a member yet? Register Sign In |