From c4b93bb32654b45260d1088571e9ed43060d7aea Mon Sep 17 00:00:00 2001 From: Ziaratban Date: Fri, 6 Mar 2020 19:53:30 +0330 Subject: [PATCH 1/3] using ActiveQuery::exists() method in friendly mode --- src/ActiveRecord.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/ActiveRecord.php b/src/ActiveRecord.php index c720d94b2..818448c04 100644 --- a/src/ActiveRecord.php +++ b/src/ActiveRecord.php @@ -411,4 +411,15 @@ private function dumpBsonObject(Type $object) } return ArrayHelper::toArray($object); } + + /** + * using ActiveQuery::exists() method in friendly mode + * @param reference $object if passed then object returned based on conditions , else only checked existence in database + * @return bool return true if $conditions exists in database + */ + public static function exists($conditions, &$object = null):bool{ + if(func_num_args() === 2) + return ($object = self::findOne($conditions)) ? true : false; + return self::find()->where($conditions)->exists(); + } } From 4f0c25300f16d11179dec57d16ace1dabe544831 Mon Sep 17 00:00:00 2001 From: Ziaratban Date: Fri, 6 Mar 2020 20:04:39 +0330 Subject: [PATCH 2/3] Update ActiveRecord.php --- src/ActiveRecord.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ActiveRecord.php b/src/ActiveRecord.php index 818448c04..9e68b69ee 100644 --- a/src/ActiveRecord.php +++ b/src/ActiveRecord.php @@ -417,7 +417,7 @@ private function dumpBsonObject(Type $object) * @param reference $object if passed then object returned based on conditions , else only checked existence in database * @return bool return true if $conditions exists in database */ - public static function exists($conditions, &$object = null):bool{ + public static function exists($conditions, &$object = null){ if(func_num_args() === 2) return ($object = self::findOne($conditions)) ? true : false; return self::find()->where($conditions)->exists(); From 9ff0d287e0d62dcb534c07e5b920edbda1d2a7ae Mon Sep 17 00:00:00 2001 From: Ziaratban Date: Wed, 16 Sep 2020 18:29:40 +0430 Subject: [PATCH 3/3] Update ActiveRecord.php --- src/ActiveRecord.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ActiveRecord.php b/src/ActiveRecord.php index 9e68b69ee..0c0630724 100644 --- a/src/ActiveRecord.php +++ b/src/ActiveRecord.php @@ -419,7 +419,7 @@ private function dumpBsonObject(Type $object) */ public static function exists($conditions, &$object = null){ if(func_num_args() === 2) - return ($object = self::findOne($conditions)) ? true : false; + return ($object = self::find()->where($conditions)->one()) ? true : false; return self::find()->where($conditions)->exists(); } }