Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Producto y Carrito #1

Open
jilgue opened this issue Oct 5, 2024 · 0 comments
Open

Producto y Carrito #1

jilgue opened this issue Oct 5, 2024 · 0 comments

Comments

@jilgue
Copy link
Member

jilgue commented Oct 5, 2024

Ejemplo:

model Producto {
  id      Int      @id @default(autoincrement())
  nombre  String
  precio   Float
  carrito  CarritoProducto[]
}

model Carrito {
  id                Int                @id @default(autoincrement())
  productos         CarritoProducto[]
}

model CarritoProducto {
  id          Int      @id @default(autoincrement())
  carritoId   Int
  productoId  Int
  cantidad    Int

  carrito     Carrito  @relation(fields: [carritoId], references: [id])
  producto    Producto  @relation(fields: [productoId], references: [id])
}
const carrito = await prisma.carrito.create({
  data: {
    productos: {
      create: [
        {
          producto: {
            connect: { id: 1 }, // Conectar con el producto con id 1
          },
          cantidad: 2, // Cantidad de este producto
        },
        {
          producto: {
            connect: { id: 2 }, // Conectar con el producto con id 2
          },
          cantidad: 3, // Cantidad de este producto
        },
      ],
    },
  },
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant