Skip to content

Cannot relate HasManyRelation using insertGraph or upsertGraph #672

@koskimas

Description

@koskimas

upsertGraph uses insertGraph and expects it to do the job, but insertGraph cannot relate a HasManyRelation because it is an update operation, not an insert. insertGraph only inserts stuff.

insertGraph should throw an exception in this case and advice the user to use upsertGraph instead. upsertGraph should just work.

Thank you @Allam76 for bringing this to our attention!

Reproduction provided by @Allam76

const {up, down} = require('./migrations/20150613161239_initial_schema');

async function test(){
    await up(knex);
    var person = await Person.query().insert({id:1,firstName:"Peter",lastName:"Jackson"});
    var pet = await Animal.query().insert({id:1, name:"Mila"});
    var test = await Person.query().upsertGraph({
        id:1,
        pets:[{
            id:1
        }]
    },{relate:true}).debug();
}

test();

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions