diff --git a/Base/Model.php b/Base/Model.php index b5c0c4b..51f4410 100644 --- a/Base/Model.php +++ b/Base/Model.php @@ -327,7 +327,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \ public static function query(): ActiveQuery { $model = new ActiveQuery(static::instance()); - $model->from($model->getTable())->alias('t1'); + $model->select()->from($model->getTable())->alias('t1'); return $model; } diff --git a/Traits/QueryTrait.php b/Traits/QueryTrait.php index 1b54397..27b9c1b 100644 --- a/Traits/QueryTrait.php +++ b/Traits/QueryTrait.php @@ -40,7 +40,7 @@ abstract class QueryTrait extends Component implements ActiveQueryInterface, ISq protected bool $lock = FALSE; protected SqlBuilder $builder; protected array $params = []; - protected array $_alias = ['t1.*']; + protected array $_alias = []; /** @@ -74,6 +74,20 @@ abstract class QueryTrait extends Component implements ActiveQueryInterface, ISq } + public function whereNotExists(Closure|string $callback, array $attributes = []): static + { + if (is_string($callback)) { + $this->where[] = $callback; + } else { + $this->where[] = 'NOT EXISTS(' . $this->makeClosureFunction($callback) . ')'; + } + if (count($attributes) > 0) { + $this->bindParams($attributes); + } + return $this; + } + + /** * @param array $select *