diff --git a/library/think/model/relation/BelongsTo.php b/library/think/model/relation/BelongsTo.php index 9b66e0c3..45118fc9 100644 --- a/library/think/model/relation/BelongsTo.php +++ b/library/think/model/relation/BelongsTo.php @@ -97,6 +97,7 @@ class BelongsTo extends OneToOne } return $this->parent->db()->alias($model) ->field($model . '.*') + ->group($model . '.' . $this->foreignKey) ->join($table . ' ' . $relation, $model . '.' . $this->foreignKey . '=' . $relation . '.' . $this->localKey, $this->joinType) ->where($where); } diff --git a/library/think/model/relation/HasMany.php b/library/think/model/relation/HasMany.php index eb9bf66d..ccc210e3 100644 --- a/library/think/model/relation/HasMany.php +++ b/library/think/model/relation/HasMany.php @@ -271,6 +271,7 @@ class HasMany extends Relation } return $this->parent->db()->alias($model) ->field($model . '.*') + ->group($model . '.' . $this->localKey) ->join($table . ' ' . $relation, $model . '.' . $this->localKey . '=' . $relation . '.' . $this->foreignKey) ->where($where); }