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

Bug report: Important bug in is_unique with DBGroup different than defined in $defaultGroup #1326

Closed
nowackipawel opened this issue Oct 18, 2018 · 0 comments

Comments

@nowackipawel
Copy link
Contributor

nowackipawel commented Oct 18, 2018

My database config is:


public $defaultGroup = 'defaultZT';

public $defaultZT = ['my old database credentials'];

public $defaultNEW = ['my new database credentials'];


and simple model class...

class AdminGroupModel extends \CodeIgniter\Model
{
	protected $DBGroup 		= 'defaultNEW';
	protected $table 		= 't_admin_group';
	protected $primaryKey 	= 'agr_identifier';
	protected $returnType 	= 'App\Entities\Admin\AdminGroup';

	protected $allowedFields = [
		'agr_identifier',
		'agr_description'
	];

	protected $validationRules = [
		'agr_identifier' 	=> 'required|min_length[1]|max_length[16]|regex_match[/[0-9a-zA-Z]{1,16}/]|is_unique[t_admin_group.agr_identifier,agr_identifier,{agr_identifier}]',
		'agr_description' 	=> 'required|max_length[512]',
	];
}


When I am trying to save (new \AdminGroupModel)->save($entity); i get an exception:

mysqli_sql_exception #1146
Table 'myolddatabasename.t_admin_group' doesn't exist

which obviously means it tried to connect my old database.... i noticed that validation rule is_unique causes this exception.

nowackipawel added a commit to nowackipawel/ci4-old that referenced this issue Oct 24, 2018
Fixes codeigniter4#1326  - passing DBGroup do Validation.
nowackipawel added a commit to nowackipawel/ci4-old that referenced this issue Oct 24, 2018
Adding DBGroup to $data and passing it to processRules. codeigniter4#1326
nowackipawel added a commit to nowackipawel/ci4-old that referenced this issue Oct 24, 2018
Finally passing correct DBGroup to Database::connect; codeigniter4#1326
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

1 participant