Skip to content

Commit 5b2c9b9

Browse files
committed
增加refresh方法
1 parent f3517ec commit 5b2c9b9

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/Model.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ public function save(array | object $data = [], $where = []): bool
306306

307307
$data = $this->getData();
308308
$origin = $this->getOrigin();
309-
$allow = $this->getOption('allow') ?: array_keys($this->getFields());
309+
$allow = $this->getOption('field') ?: array_keys($this->getFields());
310310
$readonly = $this->getOption('readonly');
311311
$disuse = $this->getOption('disuse');
312312
$allow = array_diff($allow, $readonly, $disuse);
@@ -422,6 +422,18 @@ public function isSimple(): bool
422422
return false;
423423
}
424424

425+
/**
426+
* 刷新模型数据.
427+
*
428+
* @return $this
429+
*/
430+
public function refresh()
431+
{
432+
$data = $this->getQuery()->find($this->getKey())->getData();
433+
$this->data($data);
434+
return $this;
435+
}
436+
425437
/**
426438
* 保存多个数据到当前数据对象
427439
*

src/model/concern/DbConnect.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ private function initDb()
5353
$db = Db::connect($connection);
5454
}
5555

56-
$db = $db->name($this->getName())->pk($this->getOption('pk'));
56+
$db = $db->name($this->getName())->pk($this->getPk());
57+
$autoInc = $this->getOption('autoInc');
58+
if ($autoInc) {
59+
$db->autoinc(is_string($autoInc) ? $autoInc : $this->getPk());
60+
}
5761

5862
if ($this->getOption('table')) {
5963
$db->table($this->getOption('table'));

0 commit comments

Comments
 (0)