Skip to content

upsertGraph with compound key in relation #517

@mattboutet

Description

@mattboutet

It appears that in some cases upsertGraph isn't inserting rows. Example:

My Preferences model was set up with table.primary(['userId', 'category']) and below is what I'm trying:

const prefs = [{ category: 'sms', setting: 'off' }, { category: 'sound', setting: 'off' }];
Users.query().upsertGraph({ id: user.id, preferences }).asCallback((err, updated) => {

    console.log(updated);
});

Will log:

Users {
  id: 23,
  preferences: 
   [ Preferences { category: 'sms', setting: 'nope', userId: 23 },
     Preferences { category: 'loudNoises', setting: 'nope', userId: 23 } ] }

If there's nothing in the table, then adding a debug() to the builder chain will show that 2 selects are being generated, but no insert/updates. If there's data in the table, anything not contained in the preferences array will be deleted, but nothing gets inserted.

It could be that, because we already have the primary key (['userId', 'category']) it's not trying to do the insert but because the row doesn't exist, it's not trying to update?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions