You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 2, 2025. It is now read-only.
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.
0 commit comments