-
-
Notifications
You must be signed in to change notification settings - Fork 192
Model rules for default values #420
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
base: master
Are you sure you want to change the base?
Changes from 14 commits
a13b973
f9adb4c
10f8d33
2b69aa0
e0a20b9
f4cb847
6676dae
32f9c95
05b0b09
1e4d743
57f2d72
73ff305
23b4a3a
e534105
0399a42
7f51d73
c83843f
a648b93
5cda9d9
cb3d572
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -335,6 +335,49 @@ public function generateRules($table) | |
| { | ||
| $types = []; | ||
| $lengths = []; | ||
| $rules = []; | ||
| $driverName = $this->getDbDriverName(); | ||
|
|
||
| /** | ||
| * Default values | ||
| */ | ||
| $columnsDefaultNull = []; | ||
| $columnsDefaultValues = []; | ||
| foreach ($table->columns as $column) { | ||
| if (in_array($driverName, ['mysql', 'sqlite'], true)) { | ||
samdark marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /** | ||
| * text default values quote | ||
samdark marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| */ | ||
| if ($column->defaultValue !== null) { | ||
|
||
| switch ($column->type) { | ||
| case Schema::TYPE_SMALLINT: | ||
| case Schema::TYPE_INTEGER: | ||
| case Schema::TYPE_BIGINT: | ||
| case Schema::TYPE_TINYINT: | ||
| case Schema::TYPE_BOOLEAN: | ||
| case Schema::TYPE_FLOAT: | ||
| case Schema::TYPE_DOUBLE: | ||
| case Schema::TYPE_DECIMAL: | ||
| case Schema::TYPE_MONEY: | ||
| $defaultValue = $column->defaultValue; | ||
| break; | ||
| default: | ||
| $defaultValue = '\'' . $column->defaultValue . '\''; | ||
samdark marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| $columnsDefaultValues[$defaultValue][] = $column->name; | ||
| } elseif ($column->allowNull) { | ||
| $columnsDefaultNull[] = $column->name; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| foreach($columnsDefaultValues as $defaultValue => $columnNameList){ | ||
| $rules[] = "[['" . implode("', '", $columnNameList) . "'], 'default', 'value' => $defaultValue]"; | ||
| } | ||
| if ($columnsDefaultNull) { | ||
| $rules[] = "[['" . implode("', '", $columnsDefaultNull) . "'], 'default', 'value' => null]"; | ||
| } | ||
|
|
||
| foreach ($table->columns as $column) { | ||
| if ($column->autoIncrement) { | ||
| continue; | ||
|
|
@@ -373,8 +416,6 @@ public function generateRules($table) | |
| } | ||
| } | ||
| } | ||
| $rules = []; | ||
| $driverName = $this->getDbDriverName(); | ||
| foreach ($types as $type => $columns) { | ||
| if ($driverName === 'pgsql' && $type === 'integer') { | ||
| $rules[] = "[['" . implode("', '", $columns) . "'], 'default', 'value' => null]"; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.