How to insert a datum with relationship in the bank with prism 2

Asked

Viewed 31 times

0

hello, I am trying to create a record in my database, I need to enter the information of a Mikrotik but I have to relate the table of the mikrotiks to a table of subnet, when I create the Mikrotik I need to tell which subnet it belongs to, I’m using prism 2 to make the records and queries in my database. my prism create is like this:

await prisma.mikrotik.create({
  data: {
    name: rebody.name,
    ip: rebody.ip,
    netmask: mask,
    gatway: rebody.gatway,
    password: rebody.password,
    Subrede:"preciso inserir aqui qual subrede essa mikrotik pertence"
  }
})

if anyone knows how I relate this record to an existing record in the subnet table, and can help me.

1 answer

0

I asked that same question in stackoverflow in English and got an answer that worked, the author of the answer was a user named @Ryan. that was the answer he went through and worked perfectly.

If you added the subnet relation to Mikrotik, the following code should work well.

await prisma.mikrotik.create({
  data: {
    name: rebody.name,
    ip: rebody.ip,
    netmask: mask,
    gatway: rebody.gatway,
    password: rebody.password,
    Subrede: { connect: { id: 'id-subnet-desejavel } }
  }
})

Browser other questions tagged

You are not signed in. Login or sign up in order to post.