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
|
||||
{
|
||||
if (empty($param)) return null;
|
||||
$model = static::instance();
|
||||
$query = new ActiveQuery($model);
|
||||
if (empty($param)) {
|
||||
return null;
|
||||
}
|
||||
$query = new ActiveQuery($model = static::instance());
|
||||
$query->from($model->getTable())->alias('t1');
|
||||
if (is_numeric($param)) {
|
||||
$query->where([$model->getPrimary() => +$param]);
|
||||
@@ -250,8 +251,9 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
|
||||
}
|
||||
if (($data = $query->first()) === false) {
|
||||
throw new Exception($model->getLastError());
|
||||
} else {
|
||||
return $data;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user