Skip to content

Instantly share code, notes, and snippets.

@velotiotech
Created June 23, 2020 10:28
Show Gist options
  • Save velotiotech/ce11cb75fb628e562efc4a0fd35549a6 to your computer and use it in GitHub Desktop.
Save velotiotech/ce11cb75fb628e562efc4a0fd35549a6 to your computer and use it in GitHub Desktop.
const personWithPets = {
firstName: 'Matt',
lastName: 'Damon',
age: 43,
pets: [
{
name: 'Doggo',
species: 'dog'
},
{
name: 'Kat',
species: 'cat'
}
]
};
// wrap `insertGraph` call in a transaction since its creating multiple queries.
const insertedGraph = await transaction(Person.knex(), trx => {
return (
Person.query(trx).insertGraph(personWithPets)
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment