fixed:模型name属性多加了表前缀

This commit is contained in:
JaguarJack
2020-12-01 17:55:36 +08:00
parent 94c430f491
commit 35445f37e1
2 changed files with 16 additions and 1 deletions

View File

@@ -151,6 +151,18 @@ class Utils
return \config('database.connections.mysql.prefix'); return \config('database.connections.mysql.prefix');
} }
/**
* 删除前缀
*
* @time 2020年12月01日
* @param string $table
* @return string|string[]
*/
public static function tableWithoutPrefix(string $table)
{
return str_replace(self::tablePrefix(), '', $table);
}
/** /**
* 是否是超级管理员 * 是否是超级管理员
* *

View File

@@ -11,6 +11,7 @@ use catcher\generate\build\classes\Uses;
use catcher\generate\build\types\Arr; use catcher\generate\build\types\Arr;
use catcher\traits\db\BaseOptionsTrait; use catcher\traits\db\BaseOptionsTrait;
use catcher\traits\db\ScopeTrait; use catcher\traits\db\ScopeTrait;
use catcher\Utils;
use think\facade\Db; use think\facade\Db;
use think\helper\Str; use think\helper\Str;
@@ -80,7 +81,9 @@ class Model extends Factory
} }
$class->addProperty( $class->addProperty(
(new Property('name'))->default($table)->docComment('// 表名') (new Property('name'))->default(
Utils::tableWithoutPrefix($table)
)->docComment('// 表名')
); );
$class->when($this->hasTableExists($table), function ($class) use ($table){ $class->when($this->hasTableExists($table), function ($class) use ($table){