修复主键为字符串时返回0的问题

This commit is contained in:
walkor 2023-05-16 11:16:46 +08:00
parent 5d3ce0ff12
commit ca2af73a2c
2 changed files with 15 additions and 3 deletions

View File

@ -563,6 +563,7 @@ class TableController extends Base
$pk = 'id'; $pk = 'id';
$properties = ''; $properties = '';
$timestamps = ''; $timestamps = '';
$incrementing = '';
$columns = []; $columns = [];
try { try {
$database = config('database.connections')['plugin.admin.mysql']['database']; $database = config('database.connections')['plugin.admin.mysql']['database'];
@ -571,6 +572,18 @@ class TableController extends Base
if ($item->COLUMN_KEY === 'PRI') { if ($item->COLUMN_KEY === 'PRI') {
$pk = $item->COLUMN_NAME; $pk = $item->COLUMN_NAME;
$item->COLUMN_COMMENT .= "(主键)"; $item->COLUMN_COMMENT .= "(主键)";
if (strpos(strtolower($item->DATA_TYPE), 'int') === false) {
$incrementing = <<<EOF
/**
* Indicates if the model's ID is auto-incrementing.
*
* @var bool
*/
public \$incrementing = false;
EOF;
;
}
} }
$type = $this->getType($item->DATA_TYPE); $type = $this->getType($item->DATA_TYPE);
$properties .= " * @property $type \${$item->COLUMN_NAME} {$item->COLUMN_COMMENT}\n"; $properties .= " * @property $type \${$item->COLUMN_NAME} {$item->COLUMN_COMMENT}\n";
@ -585,6 +598,7 @@ class TableController extends Base
* @var bool * @var bool
*/ */
public \$timestamps = false; public \$timestamps = false;
EOF; EOF;
} }
@ -614,9 +628,8 @@ class $class extends Base
* @var string * @var string
*/ */
protected \$primaryKey = '$pk'; protected \$primaryKey = '$pk';
$timestamps $timestamps
$incrementing
} }

View File

@ -125,7 +125,6 @@
return layui.popup.failure(res.msg); return layui.popup.failure(res.msg);
} }
return layui.popup.success("操作成功", function () { return layui.popup.success("操作成功", function () {
parent.refreshTable();
parent.layer.close(parent.layer.getFrameIndex(window.name)); parent.layer.close(parent.layer.getFrameIndex(window.name));
}); });
} }