This commit is contained in:
2021-07-06 17:58:53 +08:00
parent 40a2331626
commit ec00c2d104
2 changed files with 960 additions and 958 deletions
+7 -5
View File
@@ -29,6 +29,7 @@ use Snowflake\Abstracts\Component;
use Snowflake\Abstracts\Config; use Snowflake\Abstracts\Config;
use Snowflake\Abstracts\TraitApplication; use Snowflake\Abstracts\TraitApplication;
use Snowflake\Event as SEvent; use Snowflake\Event as SEvent;
use Snowflake\Exception\ConfigException;
use Snowflake\Exception\NotFindClassException; use Snowflake\Exception\NotFindClassException;
use Snowflake\Snowflake; use Snowflake\Snowflake;
use validator\Validator; use validator\Validator;
@@ -734,16 +735,16 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess
} }
if (str_starts_with($table, $tablePrefix)) { if (str_starts_with($table, $tablePrefix)) {
return $table; return '`' . static::getDbName() . '`' . $table;
} else if (!str_starts_with($table, '{{%')) { } else if (!str_starts_with($table, '{{%')) {
return $table; return '`' . static::getDbName() . '`' . $table;
} }
$table = trim($table, '{{%}}'); $table = trim($table, '{{%}}');
if ($tablePrefix) { if ($tablePrefix) {
$table = $tablePrefix . $table; $table = '`' . static::getDbName() . '`' . $tablePrefix . $table;
} }
return $table; return '`' . static::getDbName() . '`' . $table;
} }
@@ -1045,8 +1046,9 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess
/** /**
* @return string * @return string
* @throws ConfigException
*/ */
public static function getDbName() public static function getDbName(): string
{ {
return Config::get('databases.connections.' . static::$ab_name . '.database'); return Config::get('databases.connections.' . static::$ab_name . '.database');
} }
+1 -1
View File
@@ -137,7 +137,7 @@ trait QueryTrait
*/ */
public function getTable(): string public function getTable(): string
{ {
return '`' . $this->modelClass::getDbName() . '`' . $this->modelClass::getTable(); return $this->modelClass::getTable();
} }