This commit is contained in:
2024-12-13 14:44:00 +08:00
parent 0cc1d3d9f7
commit 7ea245fc89
2 changed files with 16 additions and 2 deletions
+1 -1
View File
@@ -327,7 +327,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
public static function query(): ActiveQuery public static function query(): ActiveQuery
{ {
$model = new ActiveQuery(static::instance()); $model = new ActiveQuery(static::instance());
$model->from($model->getTable())->alias('t1'); $model->select()->from($model->getTable())->alias('t1');
return $model; return $model;
} }
+15 -1
View File
@@ -40,7 +40,7 @@ abstract class QueryTrait extends Component implements ActiveQueryInterface, ISq
protected bool $lock = FALSE; protected bool $lock = FALSE;
protected SqlBuilder $builder; protected SqlBuilder $builder;
protected array $params = []; 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 * @param array $select
* *