Welcome Guest, Not a member yet? Register   Sign In
Validation Database Group Definition
#1

Hi,
On my Ci4 app I have split my customers tables (prefixed per customer) accross a number of databases and therefore have a number of defined database groups. I control access to the correct database and correct table prefix via session values, populated at login.
I am also using the config\validation.php for my validation rules.
However, one of my validation rules checks the database to validate the data is winthin the defined bounds.
PHP Code:
public $Division = [
  'division' => [
     'rules'  => 'required|is_not_unique[divisions.division_name]',
     'errors' => [
       'required'=> 'Division Required',
       'is_not_unique' => 'Invalid Division.'
     ]
   ],
 ]; 
Is it possible to configure the validation (or rule) away from $default database to another database group?
Reply
#2

(This post was last modified: 01-20-2022, 06:50 PM by kenjis.)

Try to add 'DBGroup' key and its value in the data to validate.

Try to use `Validation::run()` method with the third param DBGroup.

PHP Code:
run(?array $data null, ?string $group null, ?string $dbGroup null
Reply
#3

(01-20-2022, 06:44 PM)kenjis Wrote: Try to add 'DBGroup' key and its value in the data to validate.

Try to use `Validation::run()` method with the third param DBGroup.

PHP Code:
run(?array $data null, ?string $group null, ?string $dbGroup null

Many thanks,

I'll have a play with this as I also need to add the table prefix somewhere along the line.  This is very helpful.

Cheers,
Martin
Reply




Theme © iAndrew 2016 - Forum software by © MyBB