福州网站建设>网站新闻>thinkphp6专区

tp6 think-orm 2.0.53 find() 查询用bind()无法绑定到父模型解决方案

发布日期:2022-11-20浏览次数:353 来源:福州网站建设

示例:
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);
}

以上是由福州网站建设的小编为你分享了"tp6 think-orm 2.0.53 find() 查询用bind()无法绑定到父模型解决方案"文章,如果你在这方面有什么问题,随时联系我们

网友评论

  • 94技术宅 10月31日

    太感谢了,这个鬼bug让我找了一天没找着。。。

  • 卟離卟弃 10月31日

    回退版本吧,2.45跟以下应该没问题的,不然这种问题还很多

thinkphp6专区有关的文章
如果您有什么问题,欢迎咨询我们客服! 点击QQ咨询