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

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ### [](https://octobercms.com/docs/database/relations#defining-relationships)定義關系 模型關系定義為模型類上的屬性。定義關系的示例: ~~~ class User extends Model { public $hasMany = [ 'posts' => 'Acme\Blog\Models\Post' ] } ~~~ 關系像模型本身一樣,也可以充當強大的[查詢生成器](https://octobercms.com/docs/database/query),可以通過提供功能強大的方法鏈接和查詢功能的函數來訪問關系。例如: ~~~ $user->posts()->where('is_active', true)->get(); ~~~ 也可以將關系作為屬性來訪問: ~~~ $user->posts; ~~~ > **注意**:默認情況下,所有關系查詢都[啟用](https://octobercms.com/docs/database/query#in-memory-caching)了[內存中緩存](https://octobercms.com/docs/database/query#in-memory-caching)。該`load($relation)`方法不會強制刷新緩存。要重新加載內存緩存,請使用模型對象上的`reloadRelations()`或`reload()`方法。 ### [](https://octobercms.com/docs/database/relations#detailed-relationships)詳細定義 每個定義可以是一個數組,其中鍵是關系名稱,值是一個明細數組。detail數組的第一個值始終是相關的模型類名稱,而所有其他值都是必須具有鍵名的參數。 ~~~ public $hasMany = [ 'posts' => ['Acme\Blog\Models\Post', 'delete' => true] ]; ~~~ 以下是可用于所有關系的參數: | 論據 | 描述 | | --- | --- | | **order** | 多個記錄的排序順序。 | | **conditions** | 使用原始的where查詢語句過濾關系。 | | **scope** | 使用提供的范圍方法過濾關系。 | | **push** | 如果設置為false,則不會通過`push`,默認值:true保存此關系。 | | **delete** | 如果設置為true,則如果刪除主要模型或破壞關系,則將刪除相關模型,默認值:false。 | | **count** | 如果設置為true,則結果`count`僅包含用于計數關系的列,默認值:false。 | 使用**順序**和**條件的**示例過濾器: ~~~ public $belongsToMany = [ 'categories' => [ 'Acme\Blog\Models\Category', 'order' => 'name desc', 'conditions' => 'is_active = 1' ] ]; ~~~ 使用**范圍的**示例過濾器: ~~~ class Post extends Model { public $belongsToMany = [ 'categories' => [ 'Acme\Blog\Models\Category', 'scope' => 'isActive' ] ]; } class Category extends Model { public function scopeIsActive($query) { return $query->where('is_active', true)->orderBy('name', 'desc'); } } ~~~ 使用**count的**示例過濾器: ~~~ public $belongsToMany = [ 'users' => ['Backend\Models\User'], 'users_count' => ['Backend\Models\User', 'count' => true] ]; ~~~
                  <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>

                              哎呀哎呀视频在线观看