Skip to content
This repository was archived by the owner on Sep 2, 2025. It is now read-only.

Commit 3e81d0f

Browse files
committed
Updated docs
1 parent 81ae168 commit 3e81d0f

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,53 @@ app.service('/user-todos').get([1, 2]);
327327
app.service('/user-todos').get({ userId: 1, todoId: 2 });
328328
```
329329
330+
### Graph upsert
331+
Arbitrary relation graphs can be upserted (insert + update + delete) using the upsertGraph method.
332+
See [`examples`](https://vincit.github.io/objection.js/#graph-upserts) for a better explanation.
333+
Runs on the `.update(id, data, params)` service method.
334+
335+
*The relation being upserted must also be present in `allowedEager` option and included in `$eager` query.*
336+
337+
#### Options
338+
339+
* **`allowedUpsert`** - relation expression to allow relations to be upserted along with update.
340+
Defaults to `null`, meaning relations will not be automatically upserted unless specified here.
341+
See [`allowUpsert`](https://vincit.github.io/objection.js/#allowupsert) documentation.
342+
* **`upsertGraphOptions`** - See [`upsertGraphOptions`](https://vincit.github.io/objection.js/#upsertgraphoptions) documentation.
343+
344+
```js
345+
app.use('/companies', service({
346+
model: Company,
347+
allowedEager: 'clients',
348+
allowedUpsert: 'clients'
349+
})
350+
351+
app.service('/companies').update(1, {
352+
name: 'New Name',
353+
clients: [{
354+
id: 100,
355+
name: 'Existing Client'
356+
}, {
357+
name: 'New Client'
358+
}]
359+
})
360+
```
361+
362+
In the example above, we are updating the name of an existing company, along with adding a new client which is a relationship for companies. The client without the ID would be inserted and related. The client with the ID will just be updated (if there are any changes at all).
363+
364+
### Graph insert
365+
Arbitrary relation graphs can be inserted using the insertGraph method.
366+
Provides the ability to relate the inserted object with its associations.
367+
Runs on the `.create(data, params)` service method.
368+
369+
*The relation being created must also be present in `allowedEager` option and included in `$eager` query.*
370+
371+
#### Options
372+
373+
* **`allowedInsert`** - relation expression to allow relations to be created along with insert.
374+
Defaults to `null`, meaning relations will not be automatically created unless specified here.
375+
See [`allowInsert`](https://vincit.github.io/objection.js/#allowinsert) documentation.
376+
* **`insertGraphOptions`** - See [`insertGraphOptions`](https://vincit.github.io/objection.js/#insertgraphoptions) documentation.
330377
331378
## Complete Example
332379

0 commit comments

Comments
 (0)