Objection.js: Feature request: do not unrelate previously related item when upserting a graph

Created on 28 Sep 2017  路  2Comments  路  Source: Vincit/objection.js

Here is an example.
Database content:

[{
  id: 1,
  name: 'Foo',

  // This is a ManyToManyRelation
  movies: [{
    id: 1,
    title: 'Horrible Bosses',
  }, {
    id: 2,
    title: 'Wanderlust'
  }]
}]

Query:

  .query()
  .upsertGraph({
    id: 1,
     // update name:
    name: 'Bar',
    movies: [{
      // Add a relation
      id: 3,
      }, {
        // And insert another one.
        title: 'Loved it'
      }]
    }]
  });

I would like to obtain the following database state where previously related movies are still related even though not present in the graph data.

[{
  id: 1,
  name: 'Bar',
  movies: [{
    id: 1,
    title: 'Horrible Bosses',
  }, {
    id: 2,
    title: 'Wanderlust',
  }, {
    id: 3,
    title: 'Wanderlust 2',
  }, {
    id: 10,
    title: 'Loved it'
  }]
}]

Is there a way to achieve this currently? If it is not the case, could you please add such a feature?
Thank you.

discussion enhancement

Most helpful comment

@manubb @lehni The new flags are now available in the master branch. Please test them out if you have time.

All 2 comments

An option(s) for disabling any of delete/unrelate, insert/relate and update could be useful. I have to give this some thought so that we don't end up with an incoherent mess of options.

@manubb @lehni The new flags are now available in the master branch. Please test them out if you have time.

Was this page helpful?
0 / 5 - 0 ratings