tp5.0.24 MorphToOne.php 中原来方法为
/**
* 多态一对多 关联模型预查询
* @access public
* @param array $where 关联预查询条件
* @param string $relation 关联名
* @param string $subRelation 子关联
* @param bool|\Closure $closure 闭包
* @return array
*/
protected function eagerlyMorphToOne($where, $relation, $subRelation = '', $closure = false)
{
// 预载入关联查询 支持嵌套预载入
if ($closure) {
call_user_func_array($closure, [ & $this]);
}
$list = $this->query->where($where)->with($subRelation)->find();
$morphKey = $this->morphKey;
// 组装模型数据
$data = [];
foreach ($list as $set) {
$data[$set->$morphKey][] = $set;
}
return $data;
}
修改为
/**
* 多态一对一 关联模型预查询
* @access public
* @param array $where 关联预查询条件
* @param string $relation 关联名
* @param string $subRelation 子关联
* @param bool|\Closure $closure 闭包
* @return array
*/
protected function eagerlyMorphToOne($where, $relation, $subRelation = '', $closure = false)
{
// 预载入关联查询 支持嵌套预载入
if ($closure) {
call_user_func_array($closure, [ & $this]);
}
$list = $this->query->where($where)->with($subRelation)->select();
$morphKey = $this->morphKey;
// 组装模型数据
$data = [];
foreach ($list as $set) {
$data[$set->$morphKey] = $set;
}
return $data;
}