This commit is contained in:
2022-12-12 15:04:11 +08:00
parent 707e13609f
commit 78200ebffd
3 changed files with 10 additions and 16 deletions
+6 -12
View File
@@ -262,16 +262,16 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T
}
/**
* @param $param
* @param int|array|string|null $param
* @param null $db
* @return Model|null
* @throws NotFindClassException
* @throws ReflectionException
* @throws Exception
*/
public static function findOne($param, $db = NULL): static|null
public static function findOne(int|array|string|null $param, $db = NULL): static|null
{
if (is_bool($param) || is_null($param)) {
if (is_null($param)) {
return NULL;
}
if (is_numeric($param)) {
@@ -389,15 +389,9 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T
*/
protected static function deleteByCondition($condition = NULL, array $attributes = [], bool $if_condition_is_null = FALSE): bool
{
if (empty($condition)) {
if (!$if_condition_is_null) {
return FALSE;
}
return (bool)static::query()->delete();
}
$model = static::query()->ifNotWhere($if_condition_is_null)->where($condition);
if (!empty($attributes)) {
$model->bindParams($attributes);
$model = static::query();
if (!empty($condition)) {
$model->where($condition)->bindParams($attributes);
}
return (bool)$model->delete();
}
+2 -2
View File
@@ -18,11 +18,11 @@ interface ModelInterface
{
/**
* @param $param
* @param int|array|string|null $param
* @param null $db
* @return ModelInterface
*/
public static function findOne($param, $db = NULL): mixed;
public static function findOne(int|array|string|null $param, $db = NULL): mixed;
/**
+2 -2
View File
@@ -780,11 +780,11 @@ trait QueryTrait
}
/**
* @param array $params
* @param array|null $params
*
* @return $this
*/
public function bindParams(array $params = []): static
public function bindParams(?array $params = []): static
{
if (empty($params)) {
return $this;