Skip to content

Ignoring 'required' validation rule for inserts. #1773

Description

@nowackipawel

This is my code:


		$test_model = (new \TestModel);

		CLI::write('INSERT_TEST tes_id + tes_txt' , 'red');
		$test_1 = (new \App\Entities\Test());
		$test_1->tes_id = rand(20,200);
		$test_1->tes_txt = '111' . microtime();
		CLI::write(json_encode($test_1->toRawArray()));
		CLI::write($test_model->save($test_1));
		CLI::write('VALIDATION ERRORS: ' . print_r($test_model->errors(true), true));

		CLI::write('INSERT_TEST tes_id + tes_txt' , 'red');
		$test_2 = (new \App\Entities\Test());
		$test_2->tes_id = rand(20,200);
		$test_2->tes_txt = null;
		CLI::write(json_encode($test_2->toRawArray()));
		CLI::write($test_model->save($test_2));  // PRODUCES INSERT INTO `t_test` (`tes_id`) VALUES (138)

		CLI::write('VALIDATION ERRORS: ' . print_r($test_model->errors(), true)); // NO ERRORS!

and my model has validation rules like:

	protected $validationRules = [
		'tes_txt' 	=> 'required|min_length[2]',
		'tes_json' 	=> 'permit_empty|valid_json'
	];

Results for spark code:

CodeIgniter CLI Tool - Version 4.0.0-alpha.5 - Server-Time: 2019-03-01 08:55:30am

INSERT_TEST tes_id + tes_txt
{"tes_id":139,"tes_txt":"1110.12893900 1551430530","tes_json":null,"tes_created_at":null,"tes_updated_at":null}
139 INSERT INTO `t_test` (`tes_id`, `tes_txt`) VALUES (139, '1110.12893900 1551430530')
VALIDATION ERRORS: 
INSERT_TEST tes_id + tes_txt
{"tes_id":138,"tes_txt":null,"tes_json":null,"tes_created_at":null,"tes_updated_at":null}
138 INSERT INTO `t_test` (`tes_id`) VALUES (138)
VALIDATION ERRORS: 

Unfortunately as long as tes_txt = NULL $test_2 is passing validation. If I change it to '' or 'x' validation is working (required or min_length[2])

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions