Skip to content

Commit 14b501e

Browse files
committedMar 27, 2020
docs: working with relationships
1 parent 0266999 commit 14b501e

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed
 

‎docs/guide/usage.md

+25-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ if (user.$trashed()) {
1616

1717
## Deleting
1818

19-
Models can be soft deleted by calling `softDelete` directly:
19+
Models can be soft deleted by calling `softDelete` directly and passing a primary key:
2020

2121
```js
2222
await User.softDelete(1)
@@ -143,6 +143,30 @@ store.getters['entities/users/allTrashed']()
143143

144144
This is equivalent to the model query syntax: `User.query().onlyTrashed().get()`
145145

146+
### Relationships
147+
148+
Soft deleted relations respect top level modifiers and retrieving them can be accomplished in the same fashion.
149+
150+
For example, if a soft deleted `User` model has soft deleted `Post` models, you would usually execute the following query chain:
151+
152+
```js
153+
User.query().with('posts').withTrashed().get()
154+
```
155+
156+
However, in cases where you may have soft deleted relations belonging to a non-deleted parent, you can use the usual relation closure:
157+
158+
```js
159+
User.query().with('posts', (query) => {
160+
query.onlyTrashed()
161+
}).get()
162+
```
163+
164+
Using modifiers in a query chain will impact both parent and nested relations. Using relation closures is the most efficient way of retrieving soft deleted relations in most cases, particularly when using the `onlyTrashed` modifier.
165+
166+
::: tip
167+
When working with many-to-many relations, intermediate models intentionally ignore any soft delete filtering as these models are not often mutated and serve as a junction between models. This is also due to limitations in the Vuex ORM Query API.
168+
:::
169+
146170
## Restoring
147171

148172
Sometimes you may wish to "un-delete" a soft deleted model. To restore a soft deleted model into an active state, use the `$restore` method on a model instance:

0 commit comments

Comments
 (0)
Please sign in to comment.