Skip to content

Commit d0ed633

Browse files
authored
Merge pull request #30 from xgdd1987/dev
Update MakeModelCommand.php 查询表字段sql增加ORDER BY ordinal_position排序。
2 parents 2a48e1d + cd8eefc commit d0ed633

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/Commands/MakeModelCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ protected function createModel($class, $namespace, $file)
114114
$comments = $tableComment[0]->table_comment ?? $tableComment[0]->TABLE_COMMENT;
115115
$properties .= " * {$table} {$comments}" . PHP_EOL;
116116
}
117-
foreach (\support\Db::select("select COLUMN_NAME,DATA_TYPE,COLUMN_KEY,COLUMN_COMMENT from INFORMATION_SCHEMA.COLUMNS where table_name = '$table' and table_schema = '$database'") as $item) {
117+
foreach (\support\Db::select("select COLUMN_NAME,DATA_TYPE,COLUMN_KEY,COLUMN_COMMENT from INFORMATION_SCHEMA.COLUMNS where table_name = '$table' and table_schema = '$database' ORDER BY ordinal_position") as $item) {
118118
if ($item->COLUMN_KEY === 'PRI') {
119119
$pk = $item->COLUMN_NAME;
120120
$item->COLUMN_COMMENT .= "(主键)";
@@ -196,7 +196,7 @@ protected function createTpModel($class, $namespace, $file)
196196
$comments = $tableComment[0]['table_comment'] ?? $tableComment[0]['TABLE_COMMENT'];
197197
$properties .= " * {$table} {$comments}" . PHP_EOL;
198198
}
199-
foreach (\think\facade\Db::query("select COLUMN_NAME,DATA_TYPE,COLUMN_KEY,COLUMN_COMMENT from INFORMATION_SCHEMA.COLUMNS where table_name = '$table' and table_schema = '$database'") as $item) {
199+
foreach (\think\facade\Db::query("select COLUMN_NAME,DATA_TYPE,COLUMN_KEY,COLUMN_COMMENT from INFORMATION_SCHEMA.COLUMNS where table_name = '$table' and table_schema = '$database' ORDER BY ordinal_position") as $item) {
200200
if ($item['COLUMN_KEY'] === 'PRI') {
201201
$pk = $item['COLUMN_NAME'];
202202
$item['COLUMN_COMMENT'] .= "(主键)";

0 commit comments

Comments
 (0)