Skip to content

Commit 413c28e

Browse files
committed
改进Entity
1 parent 55bf241 commit 413c28e

File tree

3 files changed

+3
-4
lines changed

3 files changed

+3
-4
lines changed

src/Entity.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public function __construct(?Model $model = null)
4444
if (is_null($model)) {
4545
$class = !empty($options['model_class']) ? $options['model_class'] : str_replace('\\entity\\', '\\model\\', static::class);
4646
$model = new $class();
47+
$model->entity($this);
4748
unset($options['model_class']);
4849
}
4950

@@ -198,7 +199,7 @@ public static function __callStatic($method, $args)
198199
$db = $entity->model();
199200
} else {
200201
// 调用Query类查询方法
201-
$db = $entity->getQuery();
202+
$db = $entity->model()->getQuery();
202203
}
203204

204205
return call_user_func_array([$db, $method], $args);

src/Model.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ private function getWeakData(string $key, string $name, $default = null)
240240
*/
241241
public function newInstance(array $data = [])
242242
{
243-
$class = str_replace('\\model\\', '\\entity\\', static::class);
243+
$class = $this->getOption('entityClass', str_replace('\\model\\', '\\entity\\', static::class));
244244
$model = new static($data);
245245
$model->exists(true);
246246
if (class_exists($class) && is_subclass_of($class, Entity::class)) {

src/model/concern/ModelEvent.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ protected function trigger(string $event): bool
6666
if ($obser) {
6767
$reflect = new ReflectionClass($obser);
6868
$observer = $reflect->newinstance();
69-
} elseif ($this->getEntity() && method_exists($this->getEntity(), $method)) {
70-
$observer = $this->getEntity();
7169
} else {
7270
$observer = $this;
7371
}

0 commit comments

Comments
 (0)