修改文件、类型显示

This commit is contained in:
巴掌 committed 2020-03-26 15:30:17 +08:00
1 parent 6f5ffeb8d7
commit 7e9310e4dd
254 files changed
+5412 -4872

No files matched your search

+55 -8
View File
@@ -245,11 +245,22 @@ abstract class Model implements JsonSerializable, ArrayAccess, Arrayable, Jsonab
*/
public function newInstance(array $data = [], $where = null): Model
{
if (empty($data)) {
return new static();
$model = new static($data);
if ($this->connection) {
$model->setConnection($this->connection);
}
$model = (new static($data))->exists(true);
if ($this->suffix) {
$model->setSuffix($this->suffix);
}
if (empty($data)) {
return $model;
}
$model->exists(true);
$model->setUpdateWhere($where);
$model->trigger('AfterRead');
@@ -268,6 +279,28 @@ abstract class Model implements JsonSerializable, ArrayAccess, Arrayable, Jsonab
$this->updateWhere = $where;
}
/**
* 设置当前模型的数据库连接
* @access public
* @param string $connection 数据表连接标识
* @return $this
*/
public function setConnection(string $connection)
{
$this->connection = $connection;
return $this;
}
/**
* 获取当前模型的数据库连接标识
* @access public
* @return string
*/
public function getConnection(): string
{
return $this->connection ?: '';
}
/**
* 设置当前模型数据表的后缀
* @access public
@@ -686,13 +719,13 @@ abstract class Model implements JsonSerializable, ArrayAccess, Arrayable, Jsonab
{
$pk = $this->getPk();
if (is_string($pk) && isset($this->data[$pk])) {
$where = [[$pk, '=', $this->data[$pk]]];
$this->key = $this->data[$pk];
if (is_string($pk) && isset($this->origin[$pk])) {
$where = [[$pk, '=', $this->origin[$pk]]];
$this->key = $this->origin[$pk];
} elseif (is_array($pk)) {
foreach ($pk as $field) {
if (isset($this->data[$field])) {
$where[] = [$field, '=', $this->data[$field]];
if (isset($this->origin[$field])) {
$where[] = [$field, '=', $this->origin[$field]];
}
}
}
@@ -964,6 +997,20 @@ abstract class Model implements JsonSerializable, ArrayAccess, Arrayable, Jsonab
return $model;
}
/**
* 切换数据库连接进行查询
* @access public
* @param string $connection 数据库连接标识
* @return Model
*/
public static function connect(string $connection)
{
$model = new static();
$model->setConnection($connection);
return $model;
}
public function __call($method, $args)
{
if ('withattr' == strtolower($method)) {