Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignoring 'required' validation rule for inserts. #1773

Closed
nowackipawel opened this issue Mar 1, 2019 · 0 comments
Closed

Ignoring 'required' validation rule for inserts. #1773

nowackipawel opened this issue Mar 1, 2019 · 0 comments

Comments

@nowackipawel
Copy link
Contributor

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])

@jim-parry jim-parry added this to the 4.0.0-beta.3 milestone Mar 25, 2019
lonnieezell added a commit that referenced this issue Apr 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants