diff --git a/library/think/model/concern/Conversion.php b/library/think/model/concern/Conversion.php index b6c7cd647a..697e495bf3 100644 --- a/library/think/model/concern/Conversion.php +++ b/library/think/model/concern/Conversion.php @@ -223,13 +223,15 @@ public function jsonSerialize() * 转换数据集为数据集对象 * @access public * @param array|Collection $collection 数据集 + * @param string $resultSetType 数据集类 * @return Collection */ - public function toCollection($collection) + public function toCollection($collection, $resultSetType = null) { - if ($this->resultSetType && false !== strpos($this->resultSetType, '\\')) { - $class = $this->resultSetType; - $collection = new $class($collection); + $resultSetType = $resultSetType ?: $this->resultSetType; + + if ($resultSetType && false !== strpos($resultSetType, '\\')) { + $collection = new $resultSetType($collection); } else { $collection = new ModelCollection($collection); }