mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-08 15:42:48 +08:00
改进Query类的insert方法一处可能存在的警告错误 改进Model类一处Collection的use
This commit is contained in:
@@ -14,7 +14,7 @@ namespace think;
|
|||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use think\db\Query;
|
use think\db\Query;
|
||||||
use think\Exception\ValidateException;
|
use think\Exception\ValidateException;
|
||||||
use think\model\Collection;
|
use think\model\Collection as ModelCollection;
|
||||||
use think\model\Relation;
|
use think\model\Relation;
|
||||||
use think\model\relation\BelongsTo;
|
use think\model\relation\BelongsTo;
|
||||||
use think\model\relation\BelongsToMany;
|
use think\model\relation\BelongsToMany;
|
||||||
@@ -624,7 +624,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
/**
|
/**
|
||||||
* 转换子模型对象
|
* 转换子模型对象
|
||||||
* @access protected
|
* @access protected
|
||||||
* @param Model|Collection $model
|
* @param Model|ModelCollection $model
|
||||||
* @param $visible
|
* @param $visible
|
||||||
* @param $hidden
|
* @param $hidden
|
||||||
* @param $key
|
* @param $key
|
||||||
@@ -663,7 +663,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach ($data as $key => $val) {
|
foreach ($data as $key => $val) {
|
||||||
if ($val instanceof Model || $val instanceof Collection) {
|
if ($val instanceof Model || $val instanceof ModelCollection) {
|
||||||
// 关联模型对象
|
// 关联模型对象
|
||||||
$item[$key] = $this->subToArray($val, $visible, $hidden, $key);
|
$item[$key] = $this->subToArray($val, $visible, $hidden, $key);
|
||||||
} elseif (is_array($val) && reset($val) instanceof Model) {
|
} elseif (is_array($val) && reset($val) instanceof Model) {
|
||||||
@@ -712,14 +712,14 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
/**
|
/**
|
||||||
* 转换当前模型数据集为数据集对象
|
* 转换当前模型数据集为数据集对象
|
||||||
* @access public
|
* @access public
|
||||||
* @param array|Collection $collection 数据集
|
* @param array|\think\Collection $collection 数据集
|
||||||
* @return Collection
|
* @return \think\Collection
|
||||||
*/
|
*/
|
||||||
public function toCollection($collection)
|
public function toCollection($collection)
|
||||||
{
|
{
|
||||||
if ($this->resultSetType) {
|
if ($this->resultSetType) {
|
||||||
if ('collection' == $this->resultSetType) {
|
if ('collection' == $this->resultSetType) {
|
||||||
$collection = new Collection($collection);
|
$collection = new ModelCollection($collection);
|
||||||
} elseif (false !== strpos($this->resultSetType, '\\')) {
|
} elseif (false !== strpos($this->resultSetType, '\\')) {
|
||||||
$class = $this->resultSetType;
|
$class = $this->resultSetType;
|
||||||
$collection = new $class($collection);
|
$collection = new $class($collection);
|
||||||
|
|||||||
@@ -2065,8 +2065,10 @@ class Query
|
|||||||
$sequence = $sequence ?: (isset($options['sequence']) ? $options['sequence'] : null);
|
$sequence = $sequence ?: (isset($options['sequence']) ? $options['sequence'] : null);
|
||||||
$lastInsId = $this->getLastInsID($sequence);
|
$lastInsId = $this->getLastInsID($sequence);
|
||||||
if ($lastInsId) {
|
if ($lastInsId) {
|
||||||
$pk = $this->getPk($options);
|
$pk = $this->getPk($options);
|
||||||
$data[$pk] = $lastInsId;
|
if (is_string($pk)) {
|
||||||
|
$data[$pk] = $lastInsId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$options['data'] = $data;
|
$options['data'] = $data;
|
||||||
$this->trigger('after_insert', $options);
|
$this->trigger('after_insert', $options);
|
||||||
|
|||||||
Reference in New Issue
Block a user