definition = $this->loadService($serviceClass); } public function baseQuery(): ActiveQuery { $class = $this->definition->getEntityFqcn(); return $class::find(); } public function createQuery(): self { $this->query = $this->baseQuery(); return $this; } public function __call(string $name, $params): self { call_user_func_array([$this->query, $name], $params); return $this; } public function query() { return $this->query; } public function count() { $class = $this->definition->getEntityFqcn(); $class::groupByPrimaryKey($class, $this->query); return $this->query->count(); } public function find() { return $this->query->all(); } public function findOne() { return $this->query->one(); } public function filterById(int $id): self { $class = $this->definition->getEntityFqcn(); $this->query->andWhere([$class::tableName().'.id' => $id]); return $this; } public function filterByCondition(string $condition = ''): self { if($condition && strlen($condition) > 0) { $this->andWhere($condition); } return $this; } }