mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 07:12:47 +08:00
Model类get方法使用主键查询自动缓存
This commit is contained in:
@@ -985,6 +985,9 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
*/
|
*/
|
||||||
public static function get($data = null, $with = [], $cache = false)
|
public static function get($data = null, $with = [], $cache = false)
|
||||||
{
|
{
|
||||||
|
if (!$cache && $data && is_scalar($data)) {
|
||||||
|
$cache = true;
|
||||||
|
}
|
||||||
$query = static::parseQuery($data, $with, $cache);
|
$query = static::parseQuery($data, $with, $cache);
|
||||||
return $query->find($data);
|
return $query->find($data);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1768,8 +1768,8 @@ class Query
|
|||||||
public function update(array $data)
|
public function update(array $data)
|
||||||
{
|
{
|
||||||
$options = $this->parseExpress();
|
$options = $this->parseExpress();
|
||||||
|
$pk = $this->getPk($options);
|
||||||
if (empty($options['where'])) {
|
if (empty($options['where'])) {
|
||||||
$pk = $this->getPk($options);
|
|
||||||
// 如果存在主键数据 则自动作为更新条件
|
// 如果存在主键数据 则自动作为更新条件
|
||||||
if (is_string($pk) && isset($data[$pk])) {
|
if (is_string($pk) && isset($data[$pk])) {
|
||||||
$where[$pk] = $data[$pk];
|
$where[$pk] = $data[$pk];
|
||||||
@@ -1793,6 +1793,8 @@ class Query
|
|||||||
} else {
|
} else {
|
||||||
$options['where']['AND'] = $where;
|
$options['where']['AND'] = $where;
|
||||||
}
|
}
|
||||||
|
} elseif (is_string($pk) && isset($options['where']['AND'][$pk]) && is_scalar($options['where']['AND'][$pk])) {
|
||||||
|
$key = 'think:' . $options['table'] . '|' . $options['where']['AND'][$pk];
|
||||||
}
|
}
|
||||||
// 生成UPDATE SQL语句
|
// 生成UPDATE SQL语句
|
||||||
$sql = $this->builder()->update($data, $options);
|
$sql = $this->builder()->update($data, $options);
|
||||||
|
|||||||
Reference in New Issue
Block a user