<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                > ## 關聯預載入 > 描述:將N+1次查詢優化為兩次查詢,提高查詢性能,一對一關聯只需查詢一次,一對多關聯只需查詢兩次 ``` // 一對一關聯預載入支持兩種方式:join:0和in:1 class User extends Model { public function profile() { // 設置預載入查詢方式為IN方式 return $this->hasOne('Profile')->setEagerlyType(1); // 設置預載入查詢方式為JOIN方式 return $this->hasOne('Profile')->setEagerlyType(0); } } // 沒有用到關聯預載入(查詢4次) $list = User::all([1,2,3]); // 一次查詢 (id in (1,2,3) foreach($list as $user){ // 三次查詢 (根據user_id查出profile) // 獲取用戶關聯的profile模型數據 dump($user->profile); } // 關聯預載入方式(查詢2次) $list = User::with('profile')->select([1,2,3]); (2次查詢,一:id in (1,2,3) 二:user_id in (1,2,3)) foreach($list as $user){ // 獲取用戶關聯的profile模型數據 dump($user->profile); } // 同樣的也可以使用get和all方法進行預載入,如 $list = User::all([1,2,3],'profile,book'); // 指定查詢的字段 $list = User::field('id,name')->with(['profile'=>function($query){$query->field('email,phone');}])->select([1,2,3]); // 預載入多個關聯 $list = User::with('profile,book')->select([1,2,3]); // 嵌套預載入(遠程一對多關聯) $list = User::with('profile.phone')->select([1,2,3]); foreach($list as $user){ // 獲取用戶關聯的phone模型 dump($user->profile->phone); } // 如果要獲取子模型關聯的多個子模型(可以傳入子模型的子模型數組) $list = User::with(['profile'=>['phone','job','img']])->select([1,2,3]); foreach($list as $user){ // 獲取用戶關聯 dump($user->profile->phone); dump($user->profile->job); dump($user->profile->img); } // 關聯預載入的方法名支持用小寫字母+下劃線定義 $list = User::with('userProfile,userBook')->select([1,2,3]); 等效??于 $list = User::with('user_profile,user_book')->select([1,2,3]); ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看