This commit is contained in:
2023-07-31 23:28:59 +08:00
parent e575254139
commit 2c893a52d5
+9 -3
View File
@@ -241,8 +241,10 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T
$model->from($model->getTable())->alias('t1'); $model->from($model->getTable())->alias('t1');
if (is_numeric($param)) { if (is_numeric($param)) {
$model->where([$model->modelClass->getPrimary() => $param]); $model->where([$model->modelClass->getPrimary() => $param]);
} else { } else if (is_array($param)) {
$model->where($param); $model->where($param);
} else {
$model->whereRaw($param);
} }
return $model->first(); return $model->first();
} }
@@ -292,7 +294,11 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T
{ {
$model = new ActiveQuery(static::makeNewInstance()); $model = new ActiveQuery(static::makeNewInstance());
$model->from($model->getTable())->alias('t1'); $model->from($model->getTable())->alias('t1');
if (is_array($condition)) {
$model->where($condition); $model->where($condition);
} else {
$model->whereRaw($condition);
}
return $model->get(); return $model->get();
} }
@@ -442,12 +448,12 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T
/** /**
* @param array $old * @param array $old
* @param array|string $condition * @param array $condition
* @param array $change * @param array $change
* @return $this|bool * @return $this|bool
* @throws Exception * @throws Exception
*/ */
protected function updateInternal(array $old, array|string $condition, array $change): bool|static protected function updateInternal(array $old, array $condition, array $change): bool|static
{ {
$query = static::query()->where($condition); $query = static::query()->where($condition);
$generate = SqlBuilder::builder($query)->update($change); $generate = SqlBuilder::builder($query)->update($change);