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

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;banner(主表)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;**banner_item(從表)**&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;img(主表) ![](https://img.kancloud.cn/e7/a9/e7a97a5794f54d4aad047f6d89a73b73_160x110.png) ![](https://img.kancloud.cn/85/ef/85ef771a4f89f6feb7f371f8bfd2b79f_199x111.png) ![](https://img.kancloud.cn/09/9f/099f640b69857b39d2d3aa0bc1eb7345_216x113.png) banner(主表) VS banneritem(從表)? 一對多(主表的一個項中包含多個從表的項)? ?(hasMany) banner_item(從表) VS img(主表)? ?一對一? ? ? (belongsTo,它也是多對一)? ? 這里用hasOne會報錯 因為外鍵在banner\_item 一對多關聯的情況也比較常見,使用`hasMany`方法定義, >[info] **主表建立一對多關聯關系** >hasMany('關聯從表模型名','從表外鍵名','主表主鍵名',\['模型別名定義'\]); >返回hasMany類對象 ## **主表模型中定義關聯模型** Banner.php定義關聯模型BannerItem ``` namespace app\index\model; use think\Model; use think\Db; class Banner extends Model{ public function items(){ return $this->hasMany('BannerItem','banner_id','id'); } //將數據操作業務封裝到模型中 public static function getBannerById($id){ //TODO:根據bannerid號獲取banner信息 ->fetchSql(true) $result=self::with(['items','items.image'])->find($id); return $result; } } ``` BannerItem.php 定義關聯模型Img ``` namespace app\index\model; use think\Model; use think\Db; class BannerItem extends Model{ public function image(){ return $this->belongsTo('img','img_id','id'); } } ``` Img.php 可以是空模型 ``` namespace app\index\model; use think\Model; use think\Db; class Img extends Model{ } ``` 控制器調用 ``` \app\index\model\Banner::getBannerById(1)->toArray(); ```
                  <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>

                              哎呀哎呀视频在线观看