diff --git a/system/Model.php b/system/Model.php index 5b413ad79ad7..429ac86b9463 100644 --- a/system/Model.php +++ b/system/Model.php @@ -1233,7 +1233,7 @@ public function validate($data): bool // or an array of rules. if (is_string($this->validationRules)) { - $valid = $this->validation->run($data, $this->validationRules); + $valid = $this->validation->run($data, $this->validationRules, $this->DBGroup); } else { @@ -1241,7 +1241,7 @@ public function validate($data): bool // the value found in $data, if exists. $rules = $this->fillPlaceholders($this->validationRules, $data); - $this->validation->setRules($rules, $this->validationMessages); + $this->validation->setRules($rules, $this->validationMessages, $this->DBGroup); $valid = $this->validation->run($data); } diff --git a/system/Validation/Rules.php b/system/Validation/Rules.php index bcf1a83f52fb..8e259436695d 100644 --- a/system/Validation/Rules.php +++ b/system/Validation/Rules.php @@ -157,7 +157,7 @@ public function is_unique(string $str = null, string $field, array $data): bool // Break the table and field apart sscanf($field, '%[^.].%[^.]', $table, $field); - $db = Database::connect(); + $db = Database::connect($data['DBGroup'] ?? null); $row = $db->table($table) ->select('1') diff --git a/system/Validation/Validation.php b/system/Validation/Validation.php index 25bf46818cc4..5f10cb34ab0d 100644 --- a/system/Validation/Validation.php +++ b/system/Validation/Validation.php @@ -123,10 +123,13 @@ public function __construct($config, RendererInterface $view) * * @return bool */ - public function run(array $data = null, string $group = null): bool + public function run(array $data = null, string $group = null, string $db_group = null): bool { $data = $data ?? $this->data; + // i.e. is_unique + $data['DBGroup'] = $db_group; + $this->loadRuleSets(); $this->loadRuleGroup($group);