lji123123 5年前

修改理由:

远层比远程更加好理解吧

详细描述:

之前的版本我看都是远层。远程这个意思很怪

相关信息:


此投稿状态为 标记为已读

内容修改:

红色背景 为原始内容

绿色背景 为新增或者修改的内容

OldNewDifferences
1  
21# Eloquent: 关联
32
43- [简介](#introduction)
 
87   - [一对多 (反向)](#one-to-many-inverse)
98   - [多对多](#many-to-many)
109   - [自定义中间表模型](#defining-custom-intermediate-table-models)
11    - [远一对一](#has-one-through)
12    - [远一对多](#has-many-through)
 10   - [远一对一](#has-one-through)
 11   - [远一对多](#has-many-through)
1312- [多态关联](#polymorphic-relationships)
1413   - [一对一](#one-to-one-polymorphic-relations)
1514   - [一对多](#one-to-many-polymorphic-relations)
 
3938- [一对一](#one-to-one)
4039- [一对多](#one-to-many)
4140- [多对多](#many-to-many)
42 - [远一对一](#has-one-through)
43 - [远一对多](#has-many-through)
 41- [远一对一](#has-one-through)
 42- [远一对多](#has-many-through)
4443- [一对一 (多态关联)](#one-to-one-polymorphic-relations)
4544- [一对多 (多态关联)](#one-to-many-polymorphic-relations)
4645- [多对多 (多态关联)](#many-to-many-polymorphic-relations)
 
264263
265264   return $this->belongsToMany('App\Role', 'role_user', 'user_id', 'role_id');
266265
267 
 266
268267#### 定义反向关联
269268
270269要定义多对多的反向关联, 你只需要在关联模型中调用 `belongsToMany` 方法。我们在 `Role` 模型中定义 `users` 方法:
 
407406   public $incrementing = true;
408407
409408<a name="has-one-through"></a>
410 ### 远一对一关系
411 
412 一对一关联通过一个中间关联模型实现。
 409### 远一对一关系
 410
 411一对一关联通过一个中间关联模型实现。
413412例如,如果每个供应商都有一个用户,并且每个用户与一个用户历史记录相关联,那么供应商可以通过用户访问用户的历史记录,让我们看看定义这种关系所需的数据库表:
414413
415414   users
 
465464   }
466465
467466<a name="has-many-through"></a>
468 ### 远一对多关联
469 
470 一对多关联提供了方便、简短的方式通过中间的关联来获得远层的关联。例如,一个 `Country` 模型可以通过中间的 `User` 模型获得多个 `Post` 模型。在这个例子中,你可以轻易地收集给定国家的所有博客文章。让我们来看看定义这种关联所需的数据表:
 467### 远一对多关联
 468
 469一对多关联提供了方便、简短的方式通过中间的关联来获得远层的关联。例如,一个 `Country` 模型可以通过中间的 `User` 模型获得多个 `Post` 模型。在这个例子中,你可以轻易地收集给定国家的所有博客文章。让我们来看看定义这种关联所需的数据表:
471470
472471   countries
473472       id - integer
 
523522       }
524523   }
525524
526 
 525
527526
528527<a name="polymorphic-relationships"></a>
529528## 多态关联
 
847846
848847动态忔是「懒加载」的,这意味着它们仅在你真实访问关联数据时才被载入。因此,开发者经常使用 [预加载](#eager-loading) 预先加载那些他们确知在载入模型后将访问的关联。对载入模型关联中必定被执行的 SQL 查询而言,预加载显著减少了查询的执行次数。
849848
850 
 849
851850
852851<a name="querying-relationship-existence"></a>
853852### 查询已存在的关联
 
10281027
10291028> {note} 在约束预加载时,不能使用 `limit` 和 `take` 查询构造器方法。
10301029
1031 
 1030
10321031<a name="lazy-eager-loading"></a>
10331032### 预加载
10341033
 
12751274
12761275   $user = App\User::find(1);
12771276
1278    $user->roles()->updateExistingPivot($roleId, $attributes);
 1277   $user->roles()->updateExistingPivot($roleId, $attributes);
12791278
12801279<a name="touching-parent-timestamps"></a>
12811280## 更新父级时间戳