From 88629ec62e339792e5062a91c9637cd153fef4a6 Mon Sep 17 00:00:00 2001 From: Arisasa <1283137282@qq.com> Date: Fri, 19 Apr 2024 16:36:47 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E7=B1=BB=E5=9E=8B=E4=B8=BAmongodb=E6=97=A0=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E6=9D=A1=E4=BB=B6=E6=97=B6=E6=9F=A5=E8=AF=A2=E4=B8=8D?= =?UTF-8?q?=E5=88=B0=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 如下查询:Db::name('table')->order('id', 'DESC')->find(); mongodb调用order()方法时不会设置$this->options['order']字段,而是设置$this->options['sort']字段,导致查询失败直接返回[]。 --- src/db/BaseQuery.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/db/BaseQuery.php b/src/db/BaseQuery.php index 6f9d823c..424ed802 100644 --- a/src/db/BaseQuery.php +++ b/src/db/BaseQuery.php @@ -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); From c3188553bc67d23df198c3e73dd26040b4b246cb Mon Sep 17 00:00:00 2001 From: axguowen Date: Sat, 9 Sep 2023 09:23:42 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=85=B3=E8=81=94?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1=E5=8A=A8=E6=80=81=E8=AE=BE=E7=BD=AE=E8=A1=A8?= =?UTF-8?q?=E5=90=8E=E7=BC=80=E4=B9=8B=E5=90=8E=E5=86=99=E5=85=A5=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=97=B6=E4=B8=8D=E8=87=AA=E5=8A=A8=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E8=A1=A8=E5=90=8E=E7=BC=80=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/model/relation/HasMany.php | 2 +- src/model/relation/MorphMany.php | 2 +- src/model/relation/MorphOne.php | 2 +- src/model/relation/OneToOne.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/model/relation/HasMany.php b/src/model/relation/HasMany.php index 01854de5..7b5ad72f 100644 --- a/src/model/relation/HasMany.php +++ b/src/model/relation/HasMany.php @@ -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()); } /** diff --git a/src/model/relation/MorphMany.php b/src/model/relation/MorphMany.php index e3ba6045..a4b42db8 100644 --- a/src/model/relation/MorphMany.php +++ b/src/model/relation/MorphMany.php @@ -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()); } /** diff --git a/src/model/relation/MorphOne.php b/src/model/relation/MorphOne.php index 32ec084a..5e0e2684 100644 --- a/src/model/relation/MorphOne.php +++ b/src/model/relation/MorphOne.php @@ -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()); } /** diff --git a/src/model/relation/OneToOne.php b/src/model/relation/OneToOne.php index 0ddb7158..51063ac6 100644 --- a/src/model/relation/OneToOne.php +++ b/src/model/relation/OneToOne.php @@ -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()); } /** From 6eca2613fdb0c5c5810c948c10ffeb9d82fb8e7d Mon Sep 17 00:00:00 2001 From: Hhh0121 <2607250025@qq.com> Date: Thu, 11 May 2023 18:24:38 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=A4=9A=E6=80=81?= =?UTF-8?q?=E4=B8=80=E5=AF=B9=E5=A4=9A=E5=85=B3=E8=81=94=EF=BC=8C=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E6=9C=AA=E5=AE=9A=E4=B9=89=E6=97=B6=EF=BC=8C=E9=A2=84?= =?UTF-8?q?=E8=BD=BD=E5=85=A5=E6=9F=A5=E8=AF=A2=E6=95=B0=E6=8D=AE=E9=9B=86?= =?UTF-8?q?=E6=97=B6=E6=8A=9B=E5=87=BA=E5=BC=82=E5=B8=B8=E6=94=B9=E4=B8=BA?= =?UTF-8?q?null=EF=BC=8C=E4=B8=8E=E6=9F=A5=E8=AF=A2=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1=E5=92=8C=E5=BB=B6=E8=BF=9F=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E4=BF=9D=E6=8C=81=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/model/relation/MorphTo.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/model/relation/MorphTo.php b/src/model/relation/MorphTo.php index 6e1e837e..03638def 100644 --- a/src/model/relation/MorphTo.php +++ b/src/model/relation/MorphTo.php @@ -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) {