diff --git a/library/think/model/relation/BelongsTo.php b/library/think/model/relation/BelongsTo.php index e609a876..c1cbab97 100644 --- a/library/think/model/relation/BelongsTo.php +++ b/library/think/model/relation/BelongsTo.php @@ -52,6 +52,7 @@ class BelongsTo extends OneToOne call_user_func_array($closure, [ & $this->query]); } $relationModel = $this->query + ->removeWhereField($this->localKey) ->where($this->localKey, $this->parent->$foreignKey) ->relation($subRelation) ->find(); diff --git a/library/think/model/relation/HasOne.php b/library/think/model/relation/HasOne.php index 3c036c01..db74e4a6 100644 --- a/library/think/model/relation/HasOne.php +++ b/library/think/model/relation/HasOne.php @@ -50,7 +50,11 @@ class HasOne extends OneToOne call_user_func_array($closure, [ & $this->query]); } // 判断关联类型执行查询 - $relationModel = $this->query->where($this->foreignKey, $this->parent->$localKey)->relation($subRelation)->find(); + $relationModel = $this->query + ->removeWhereField($this->foreignKey) + ->where($this->foreignKey, $this->parent->$localKey) + ->relation($subRelation) + ->find(); if ($relationModel) { $relationModel->setParent(clone $this->parent);