diff --git a/Traits/QueryTrait.php b/Traits/QueryTrait.php index 1aecb86..0f8bcf8 100644 --- a/Traits/QueryTrait.php +++ b/Traits/QueryTrait.php @@ -75,8 +75,8 @@ abstract class QueryTrait extends Component implements ActiveQueryInterface, ISq /** - * @param Closure|string $callback - * @param array $attributes + * @param Closure|Query $callback + * @param array $attributes * * @return $this */ @@ -94,6 +94,26 @@ abstract class QueryTrait extends Component implements ActiveQueryInterface, ISq } + /** + * @param Closure|Query $callback + * @param array $attributes + * + * @return $this + */ + public function whereExists(Closure|Query $callback, array $attributes = []): static + { + if ($callback instanceof Query) { + $this->where[] = 'EXISTS(' . $callback->build() . ')'; + } else { + $this->where[] = 'EXISTS(' . $this->makeClosureFunction($callback) . ')'; + } + if (count($attributes) > 0) { + $this->bindParams($attributes); + } + return $this; + } + + /** * @param array $select *