mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
fix: validation errors in model are not cleared when running validation again
This commit is contained in:
parent
5e65c4c23c
commit
e4f1d8817a
@ -25,11 +25,6 @@ parameters:
|
||||
count: 1
|
||||
path: system/Autoloader/Autoloader.php
|
||||
|
||||
-
|
||||
message: "#^Method CodeIgniter\\\\Validation\\\\ValidationInterface\\:\\:run\\(\\) invoked with 3 parameters, 0\\-2 required\\.$#"
|
||||
count: 1
|
||||
path: system/BaseModel.php
|
||||
|
||||
-
|
||||
message: "#^Property Config\\\\Cache\\:\\:\\$backupHandler \\(string\\) in isset\\(\\) is not nullable\\.$#"
|
||||
count: 1
|
||||
|
@ -1344,7 +1344,9 @@ abstract class BaseModel
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->validation->setRules($rules, $this->validationMessages)->run($data, null, $this->DBGroup);
|
||||
$this->validation->reset()->setRules($rules, $this->validationMessages);
|
||||
|
||||
return $this->validation->run($data, null, $this->DBGroup);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -55,6 +55,29 @@ final class ValidationModelTest extends LiveModelTestCase
|
||||
$this->assertSame('You forgot to name the baby.', $errors['name']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see https://github.com/codeigniter4/CodeIgniter4/issues/5859
|
||||
*/
|
||||
public function testValidationTwice(): void
|
||||
{
|
||||
$data = [
|
||||
'name' => null,
|
||||
'description' => 'some great marketing stuff',
|
||||
];
|
||||
|
||||
$this->assertFalse($this->model->insert($data));
|
||||
|
||||
$errors = $this->model->errors();
|
||||
$this->assertSame('You forgot to name the baby.', $errors['name']);
|
||||
|
||||
$data = [
|
||||
'name' => 'some name',
|
||||
'description' => 'some great marketing stuff',
|
||||
];
|
||||
|
||||
$this->assertIsInt($this->model->insert($data));
|
||||
}
|
||||
|
||||
public function testValidationWithSetValidationRule(): void
|
||||
{
|
||||
$data = [
|
||||
|
Loading…
x
Reference in New Issue
Block a user