-
Notifications
You must be signed in to change notification settings - Fork 642
Closed
Labels
Description
I'm using [email protected] and have these models:
class Role extends Model {
static get tableName() {
return 'roles'
}
static get relationMappings() {
return {
sets: {
relation: Model.HasManyRelation,
modelClass: 'Set',
join: { from: 'roles.id', to: 'sets.roleId' },
},
}
}
}
class Set extends Model {
static get tableName() {
return 'sets'
}
static get relationMappings() {
return {
setAttributes: {
relation: Model.HasManyRelation,
modelClass: 'SetAttribute',
join: { from: 'sets.id', to: 'sets_attributes.setId' },
},
}
}
}
class SetAttribute extends Model {
static get tableName() {
return 'sets_attributes'
}
}Suppose role with ID 1 already has set with ID 1.
If I'm using upsertGraph like this, It works correctly -- new row is inserted in "sets" table:
transaction(Role.knex(), trx =>
Role.query(trx).upsertGraph({
id: 1,
sets: [{ id: 1 }, { name: 'New Set' }],
}),
)But if I pass "setAttributes" for newly created set, Objection deletes all setAttributes for the first set (with id=1):
transaction(Role.knex(), trx =>
Role.query(trx).upsertGraph({
id: 1,
sets: [
{ id: 1 },
{ name: 'New Set', setAttributes: [{ name: 'New Set Attribute' }] },
],
}),
)Is this behaviour expected?