Skip to content

Commit

Permalink
Merge branch '3.0' of github.com:top-think/think-orm into 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
liu21st committed Jun 25, 2024
2 parents fed3f23 + 6eca261 commit 4bd05de
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/db/BaseQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -1355,7 +1355,7 @@ public function find($data = null)
$this->parsePkWhere($data);
}

if (empty($this->options['where']) && empty($this->options['order'])) {
if (empty($this->options['where']) && empty($this->options['order']) && empty($this->options['sort'])) {
$result = [];
} else {
$result = $this->connection->find($this);
Expand Down
2 changes: 1 addition & 1 deletion src/model/relation/HasMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public function make(array|Model $data = []): Model
// 保存关联表数据
$data[$this->foreignKey] = $this->parent->{$this->localKey};

return new $this->model($data);
return (new $this->model($data))->setSuffix($this->getModel()->getSuffix());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/model/relation/MorphMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ public function make($data = []): Model
$data[$this->morphKey] = $this->parent->$pk;
$data[$this->morphType] = $this->type;

return new $this->model($data);
return (new $this->model($data))->setSuffix($this->getModel()->getSuffix());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/model/relation/MorphOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public function make(array|Model $data = []): Model
$data[$this->morphKey] = $this->parent->$pk;
$data[$this->morphType] = $this->type;

return new $this->model($data);
return (new $this->model($data))->setSuffix($this->getModel()->getSuffix());
}

/**
Expand Down
22 changes: 12 additions & 10 deletions src/model/relation/MorphTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,18 +243,20 @@ public function eagerlyResultSet(array &$resultSet, string $relation, array $sub
foreach ($range as $key => $val) {
// 多态类型映射
$model = $this->parseModel($key);
$obj = new $model();
if (!is_null($closure)) {
$obj = $closure($obj);
}
$pk = $obj->getPk();
$list = $obj->with($subRelation)
->cache($cache[0] ?? false, $cache[1] ?? null, $cache[2] ?? null)
->select($val);
$data = [];
if (class_exists($model)) {
$obj = new $model();
if (!is_null($closure)) {
$obj = $closure($obj);
}
$pk = $obj->getPk();
$list = $obj->with($subRelation)
->cache($cache[0] ?? false, $cache[1] ?? null, $cache[2] ?? null)
->select($val);

foreach ($list as $k => $vo) {
$data[$vo->$pk] = $vo;
foreach ($list as $k => $vo) {
$data[$vo->$pk] = $vo;
}
}

foreach ($resultSet as $result) {
Expand Down
2 changes: 1 addition & 1 deletion src/model/relation/OneToOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public function make(array|Model $data = []): Model
// 保存关联表数据
$data[$this->foreignKey] = $this->parent->{$this->localKey};

return new $this->model($data);
return (new $this->model($data))->setSuffix($this->getModel()->getSuffix());
}

/**
Expand Down

0 comments on commit 4bd05de

Please sign in to comment.