Skip to content

Commit

Permalink
改进模型类的db方法
Browse files Browse the repository at this point in the history
Query类getFields方法增加tableName参数
  • Loading branch information
liu21st committed Jun 2, 2019
1 parent 388a3a7 commit 3e8655e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/think/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
class App extends Container
{
const VERSION = '6.0.0RC2';
const VERSION = '6.0.0RC3';

/**
* 应用调试模式
Expand Down
17 changes: 8 additions & 9 deletions src/think/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,16 +323,16 @@ public function db($scope = []): Query
$query = $this->db->buildQuery($this->connection)
->name($this->name . $this->suffix)
->pk($this->pk);

if (!empty($this->table)) {
$query->table($this->table . $this->suffix);
}
}

$query->model($this)
->json($this->json, $this->jsonAssoc)
->setFieldType(array_merge($this->schema, $this->jsonType));

if (!empty($this->table)) {
$query->table($this->table . $this->suffix);
}

// 软删除
if (property_exists($this, 'withTrashed') && !$this->withTrashed) {
$this->withNoTrashed($query);
Expand Down Expand Up @@ -974,12 +974,11 @@ public static function withoutGlobalScope(array $scope = null)
* @param string $suffix 切换的表后缀
* @return Model
*/
public static function change(string $suffix)
{
$model = new static();
$model->setSuffix($suffix);
function switch (string $suffix) {
$model = new static();
$model->setSuffix($suffix);

return $model;
return $model;
}

public function __call($method, $args)
Expand Down
5 changes: 3 additions & 2 deletions src/think/db/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,12 @@ public function setFieldType(array $type)
/**
* 获取详细字段类型信息
* @access public
* @param string $tableName 数据表名称
* @return array
*/
public function getFields(): array
public function getFields(string $tableName = ''): array
{
return $this->connection->getFields($this->getTable());
return $this->connection->getFields($tableName ?: $this->getTable());
}

/**
Expand Down

0 comments on commit 3e8655e

Please sign in to comment.