From df1938c4331fcbd71248dfcb010b318d868e9893 Mon Sep 17 00:00:00 2001 From: Wolf Wortmann <7399618+element-code@users.noreply.github.com> Date: Wed, 27 May 2020 16:03:23 +0200 Subject: [PATCH] Fix: Model::getValidationRules() return when using shared rules This should fix https://github.com/codeigniter4/CodeIgniter4/issues/3039 . --- system/Model.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/system/Model.php b/system/Model.php index f4a58f9f4de5..5543a262a374 100644 --- a/system/Model.php +++ b/system/Model.php @@ -1438,7 +1438,9 @@ public function cleanRules(bool $choice = false) */ public function validate($data): bool { - if ($this->skipValidation === true || empty($this->validationRules) || empty($data)) + $rules = $this->getValidationRules(); + + if ($this->skipValidation === true || empty($rules) || empty($data)) { return true; } @@ -1450,8 +1452,6 @@ public function validate($data): bool $data = (array) $data; } - $rules = $this->validationRules; - // ValidationRules can be either a string, which is the group name, // or an array of rules. if (is_string($rules)) @@ -1580,6 +1580,13 @@ protected function fillPlaceholders(array $rules, array $data): array public function getValidationRules(array $options = []): array { $rules = $this->validationRules; + + // ValidationRules can be either a string, which is the group name, + // or an array of rules. + if (is_string($rules)) + { + $rules = $this->validation->loadRuleGroup($rules); + } if (isset($options['except'])) {