福州網(wǎng)站建設(shè)>網(wǎng)站新聞>thinkphp6專區(qū)

        tp6 think-orm 2.0.53 find() 查詢用bind()無法綁定到父模型解決方案

        發(fā)布日期:2022-11-20瀏覽次數(shù):527 來源:福州網(wǎng)站建設(shè)

        示例:
        GoodsModel::where('id', $id)->with([
        'detail' => function ($query) {
        $query->bind(['detail' => 'detail']);
        }])->find();
        這樣把關(guān)聯(lián)屬性綁定到父模型沒效果,但只要把find()改成select()就是沒問題的,經(jīng)過大半天排查,發(fā)現(xiàn)問題出在下面

        think\model\relation\HasOne;
        修改文件 278行
        原代碼:
        $result->setRelation($relation, $relationModel);

        if (!empty($this->bindAttr)) {
        // 綁定關(guān)聯(lián)屬性
        $this->bindAttr($result, $relationModel);
        }
        改成:
        if (!empty($this->bindAttr)) {
        // 綁定關(guān)聯(lián)屬性
        $this->bindAttr($result, $relationModel);
        } else {
        $result->setRelation($relation, $relationModel);
        }

        以上是由福州網(wǎng)站建設(shè)的小編為你分享了"tp6 think-orm 2.0.53 find() 查詢用bind()無法綁定到父模型解決方案"文章,如果你在這方面有什么問題,隨時聯(lián)系我們

        網(wǎng)友評論

        • 94技術(shù)宅 10月31日

          太感謝了,這個鬼bug讓我找了一天沒找著。。。

        • 卟離卟棄 10月31日

          回退版本吧,2.45跟以下應(yīng)該沒問題的,不然這種問題還很多

        thinkphp6專區(qū)有關(guān)的文章
        如果您有什么問題,歡迎咨詢我們客服! 點擊QQ咨詢