How can I insert two records with the second using...
# orm-help
p
How can I insert two records with the second using the result of the first. Like adding an invoice with line items. Need to have the invoice number before inserting the line items. I tried the below, but it’s a hot mess I know. EDIT: figured it out. Below works:
Copy code
const addedDate = new Date().toISOString();
const noteAdded = prisma.note.create({
  data: {
    description: description,
    title: title,
    active: 1,
    createDate: addedDate,
    noteChangeLogs: {
      create: [
        {
          changeDate: addedDate,
          operation: 'Created',
          details: '',
        },
      ],
    },
  },
  include: {
    noteChangeLogs: true, // Include all posts in the returned object
  },
});
This was helpful: https://www.prisma.io/docs/concepts/components/prisma-client/relation-queries
πŸ‘ 1
r
@Peter Kellner πŸ‘‹ You can also do that with long running transactions that we have recently introduced πŸ™‚ https://github.com/prisma/prisma/releases/tag/2.29.0