eee
This commit is contained in:
+6
-4
@@ -237,9 +237,10 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
|
|||||||
*/
|
*/
|
||||||
public static function findOne(int|string|array|null $param): ?static
|
public static function findOne(int|string|array|null $param): ?static
|
||||||
{
|
{
|
||||||
if (empty($param)) return null;
|
if (empty($param)) {
|
||||||
$model = static::instance();
|
return null;
|
||||||
$query = new ActiveQuery($model);
|
}
|
||||||
|
$query = new ActiveQuery($model = static::instance());
|
||||||
$query->from($model->getTable())->alias('t1');
|
$query->from($model->getTable())->alias('t1');
|
||||||
if (is_numeric($param)) {
|
if (is_numeric($param)) {
|
||||||
$query->where([$model->getPrimary() => +$param]);
|
$query->where([$model->getPrimary() => +$param]);
|
||||||
@@ -250,8 +251,9 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
|
|||||||
}
|
}
|
||||||
if (($data = $query->first()) === false) {
|
if (($data = $query->first()) === false) {
|
||||||
throw new Exception($model->getLastError());
|
throw new Exception($model->getLastError());
|
||||||
|
} else {
|
||||||
|
return $data;
|
||||||
}
|
}
|
||||||
return $data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user