<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>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                遠程一對多關聯用于定義有跨表的一對多關系,例如: * 每個城市有多個用戶 * 每個用戶有多個話題 * 城市和話題之間并無關聯 ## 關聯定義 就可以直接通過遠程一對多關聯獲取每個城市的多個話題,`City`模型定義如下: ~~~ <?php namespace app\model; use think\Model; class City extends Model { public function topics() { return $this->hasManyThrough(Topic::class, User::class); } } ~~~ >[danger] 遠程一對多關聯,需要同時存在`Topic`和`User`模型,當前模型和中間模型的關聯關系可以是一對一或者一對多。 `hasManyThrough`方法的參數如下: >[info] ### hasManyThrough('關聯模型', '中間模型', '外鍵', '中間表關聯鍵','當前模型主鍵','中間模型主鍵'); * **關聯模型**(必須):關聯模型類名 * **中間模型**(必須):中間模型類名 * **外鍵**:默認的外鍵名規則是當前模型名+`_id` * **中間表關聯鍵**:默認的中間表關聯鍵名的規則是中間模型名+`_id` * **當前模型主鍵**:一般會自動獲取也可以指定傳入 * **中間模型主鍵**:一般會自動獲取也可以指定傳入 ## 關聯查詢 我們可以通過下面的方式獲取關聯數據 ~~~ $city = City::find(1); // 獲取同城的所有話題 dump($city->topics); // 也可以進行條件搜索 dump($city->topics()->where('topic.status',1)->select()); ~~~ > 條件搜索的時候,需要帶上模型名作為前綴 ### 根據關聯條件查詢 如果需要根據關聯條件來查詢當前模型,可以使用 ``` $list = City::hasWhere('topics', ['status' => 1])->select(); ``` 更復雜的查詢條件可以使用 ``` $where = Topic::where('status', 1)->where('title', 'like', '%think%'); $list = City::hasWhere('topics',$where)->select(); ```
                  <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>

                              哎呀哎呀视频在线观看