diff --git a/library/think/db/Connection.php b/library/think/db/Connection.php index c18cec0f..babd6ba8 100644 --- a/library/think/db/Connection.php +++ b/library/think/db/Connection.php @@ -700,6 +700,16 @@ abstract class Connection return $this->linkID->lastInsertId($sequence); } + /** + * 获取返回或者影响的记录数 + * @access public + * @return integer + */ + public function getNumRows() + { + return $this->numRows; + } + /** * 获取最近的错误信息 * @access public diff --git a/library/think/db/Query.php b/library/think/db/Query.php index f92ffb04..84f0edcb 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -1883,7 +1883,7 @@ class Query } // 返回结果处理 - if ($resultSet) { + if ($this->connection->getNumRows()) { // 数据列表读取后的处理 if (!empty($this->model)) { // 生成模型对象 @@ -1898,7 +1898,7 @@ class Query } $resultSet[$key] = $result; } - if (!empty($options['with'])) { + if (!empty($options['with']) && $result instanceof Model) { // 预载入 $resultSet = $result->eagerlyResultSet($resultSet, $options['with'], is_object($resultSet) ? get_class($resultSet) : ''); }