Skip to content

Commit

Permalink
refactor: small improvements to sync method PR
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Sep 25, 2021
1 parent 6e15805 commit 6250d9d
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions content/reference/orm/relations/many-to-many.md
Original file line number Diff line number Diff line change
Expand Up @@ -547,14 +547,15 @@ await user

In the above example, the `sync` method will only keep the projects with the mentioned ids and removes the other ones.

You can change this behavior by passing false to the second argument of sync method, then it will attach the given projects without detaching the others. This is useful when you want to attach only if it's not already attached.
You can change this behavior by passing `false` as the second argument to the `sync` method, and then it will attach the mentioned ids without detaching the others.

In the following example, the `sync` method will attach (only if they aren't already) the projects with the id of **"1"** and **"2"** without detaching any existing ids.

```ts
await user
.related('projects')
.sync([1, 2],false)
.sync([1, 2], false)
```
In the above example, the `sync` method will attach (only if they aren't already) the projects 1 and 2 without detaching the others.

You can also perform a sync with pivot attributes.

Expand Down

0 comments on commit 6250d9d

Please sign in to comment.