Skip to content

Commit

Permalink
with method
Browse files Browse the repository at this point in the history
  • Loading branch information
curder committed Nov 15, 2023
1 parent 5527a77 commit 33c13c4
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions docs/partials/model-relations.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,23 @@ $post->comments()->saveMany([
// Author -> belongsTo(Country::class)

$users = Book::with('author.country')->get();
```

## 使用精确列进行预加载

执行预加载时可以指定想要从关系中获取的确切列。

```php
// Book -> belongsTo(Author::class)

$users = Book::with('author:id,name')->get();
```

即使在更深层次的嵌套关系中也可以获取确切列:

```php
// Book -> belongsTo(Author::class)
// Author -> belongsTo(Country::class)

$users = Book::with('author.country:id,name')->get();
```

0 comments on commit 33c13c4

Please sign in to comment.