-
Notifications
You must be signed in to change notification settings - Fork 642
Closed
Labels
Description
ObjectionJS: 0.8.6
Knex: 0.13.0
NodeJS: 7.10.1
I have two tables with many to many relationship:
programs(id, name)
groups(id, name)
program_group(program_id, group_id)
These are mapped models:
class Group {
....
}
class Program {
static relationMappings = {
groups: {
relation: Model.ManyToManyRelation,
modelClass: Group,
join: {
from: 'programs.id',
through: {
from: program_group.program_id',
to: ''program_group.group_id'
},
to: 'groups.id'
}
}
}
....
}
When I run this code
Program.query().upsertGraph({
id: programId,
groups: {
id: groupId
}
},
{
relate: true,
unrelate: true
})
The executed queries are:
select "programs"."id" from "programs" where "programs"."id" in ($1)
select "program_group"."program_id" as "objectiontmpjoin0", "groups"."id" from "groups" inner join "program_group" on "program_group"."group_id" = "groups"."id" where "program_group"."program_id" in ($1)
insert into "program_group" ("group_id", "program_id") values ($1, $2) returning "program_id"
update "programs" set "id" = $1 where "programs"."id" = $2
My questions:
- The last update seems to be unnecessary, does it?
- I just want to execute the
insert into "program_group"(kinda blindly insert) without the other above queries. How do I achieve that?