From be7ad0e4d60d3d6e5c116258062789e36edb35c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Mon, 16 Aug 2021 11:27:55 +0800 Subject: [PATCH] e --- src/ActiveRecord.php | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/ActiveRecord.php b/src/ActiveRecord.php index 0cb754e..05138a6 100644 --- a/src/ActiveRecord.php +++ b/src/ActiveRecord.php @@ -13,9 +13,9 @@ namespace Database; use Database\Base\BaseActiveRecord; use Database\Traits\HasBase; use Exception; -use ReflectionException; use Kiri\Exception\NotFindClassException; use Kiri\Kiri; +use ReflectionException; defined('SAVE_FAIL') or define('SAVE_FAIL', 3227); defined('FIND_OR_CREATE_MESSAGE') or define('FIND_OR_CREATE_MESSAGE', 'Create a new model, but the data cannot be empty.'); @@ -241,6 +241,32 @@ class ActiveRecord extends BaseActiveRecord return $condition->batchUpdate($attributes); } + + /** + * @param $condition + * @return ActiveRecord|null + * @throws NotFindClassException + * @throws ReflectionException + * @throws Exception + */ + public static function first($condition): ?ActiveRecord + { + return static::query()->where($condition)->first(); + } + + + /** + * @param $condition + * @return array|Collection + * @throws NotFindClassException + * @throws ReflectionException + */ + public static function get($condition): Collection|array + { + return static::query()->where($condition)->all(); + } + + /** * @param $condition * @param array $attributes