This commit is contained in:
2024-12-13 15:03:09 +08:00
parent db92238e9e
commit 42af2e8bf9
+21 -1
View File
@@ -75,7 +75,7 @@ abstract class QueryTrait extends Component implements ActiveQueryInterface, ISq
/** /**
* @param Closure|string $callback * @param Closure|Query $callback
* @param array $attributes * @param array $attributes
* *
* @return $this * @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 * @param array $select
* *