变更
This commit is contained in:
+6
-12
@@ -262,16 +262,16 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $param
|
* @param int|array|string|null $param
|
||||||
* @param null $db
|
* @param null $db
|
||||||
* @return Model|null
|
* @return Model|null
|
||||||
* @throws NotFindClassException
|
* @throws NotFindClassException
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
* @throws Exception
|
* @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;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (is_numeric($param)) {
|
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
|
protected static function deleteByCondition($condition = NULL, array $attributes = [], bool $if_condition_is_null = FALSE): bool
|
||||||
{
|
{
|
||||||
if (empty($condition)) {
|
$model = static::query();
|
||||||
if (!$if_condition_is_null) {
|
if (!empty($condition)) {
|
||||||
return FALSE;
|
$model->where($condition)->bindParams($attributes);
|
||||||
}
|
|
||||||
return (bool)static::query()->delete();
|
|
||||||
}
|
|
||||||
$model = static::query()->ifNotWhere($if_condition_is_null)->where($condition);
|
|
||||||
if (!empty($attributes)) {
|
|
||||||
$model->bindParams($attributes);
|
|
||||||
}
|
}
|
||||||
return (bool)$model->delete();
|
return (bool)$model->delete();
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -18,11 +18,11 @@ interface ModelInterface
|
|||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $param
|
* @param int|array|string|null $param
|
||||||
* @param null $db
|
* @param null $db
|
||||||
* @return ModelInterface
|
* @return ModelInterface
|
||||||
*/
|
*/
|
||||||
public static function findOne($param, $db = NULL): mixed;
|
public static function findOne(int|array|string|null $param, $db = NULL): mixed;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -780,11 +780,11 @@ trait QueryTrait
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $params
|
* @param array|null $params
|
||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function bindParams(array $params = []): static
|
public function bindParams(?array $params = []): static
|
||||||
{
|
{
|
||||||
if (empty($params)) {
|
if (empty($params)) {
|
||||||
return $this;
|
return $this;
|
||||||
|
|||||||
Reference in New Issue
Block a user