diff --git a/library/think/model/relation/BelongsTo.php b/library/think/model/relation/BelongsTo.php index 4765811e..ebef780c 100644 --- a/library/think/model/relation/BelongsTo.php +++ b/library/think/model/relation/BelongsTo.php @@ -128,6 +128,7 @@ class BelongsTo extends OneToOne } if (!empty($range)) { + $this->query->removeWhereField($localKey); $data = $this->eagerlyWhere($this->query, [ $localKey => [ 'in', diff --git a/library/think/model/relation/HasOne.php b/library/think/model/relation/HasOne.php index 46fedb87..dad8a7f2 100644 --- a/library/think/model/relation/HasOne.php +++ b/library/think/model/relation/HasOne.php @@ -130,7 +130,8 @@ class HasOne extends OneToOne } if (!empty($range)) { - $data = $this->eagerlyWhere($this, [ + $this->query->removeWhereField($foreignKey); + $data = $this->eagerlyWhere($this->query, [ $foreignKey => [ 'in', $range,