GoodsModel::where('id', $id)->with([
'detail' => function ($query) {
$query->bind(['detail' => 'detail']);
}])->find();
这样把关联属性绑定到父模型没效果,但只要把find()改成select()就是没问题的,经过大半天排查,发现问题出在下面
think\model\relation\HasOne;
修改文件 278行
原代码:
$result->setRelation($relation, $relationModel);
if (!empty($this->bindAttr)) {
// 绑定关联属性
$this->bindAttr($result, $relationModel);
}
改成:
if (!empty($this->bindAttr)) {
// 绑定关联属性
$this->bindAttr($result, $relationModel);
} else {
$result->setRelation($relation, $relationModel);
}
最佳答案