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

bit, tinyint to boolean #172

Open
optmsp opened this issue Aug 15, 2021 · 0 comments
Open

bit, tinyint to boolean #172

optmsp opened this issue Aug 15, 2021 · 0 comments

Comments

@optmsp
Copy link

optmsp commented Aug 15, 2021

I am using MySQL. To represent a boolean value, I need to use MySQL bool (which appears to just by tinyint) or a bit (0/1). I prefer using bit, but it doesn't appear that this is supported by the yii2 table schema. (Correct me if wrong because that would solve this directly.)

Anyway, if I run gii/enhanced-gii-model against a column of tinyint, it is creating a rules[] with a type of string and max of 1. That will break normal code trying to use the field as a boolean. To fix this, I change yii2-enhanced-gii/model/Generator.php like so:

case Schema::TYPE_TINYINT:
	echo "default.. column: " . $column->name . "\n";
	echo "type: " . $column->type . "\n";
	$types['boolean'][] = $column->name;
	break;

yii2-enhanced-gii now produces this output:

[['oplock', 'is_active'], 'boolean'],

Which is correct (for my situation).

Is there a better way? If not, would you be open to a PR to implement this with a switch like --use-tinyint-as-boolean ?

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