`model Order {` `id Int @i...
# orm-help
l
model Order {
id             Int         @id @unique @default(autoincrement())
products       Product[]   @relation(references: [id])
}
model Product {
id             Int         @id @unique @default(autoincrement())
orders         Order[]     // Why do I need this here? I don't really care about this, I only care about the above, products in an order. Can I get rid of this line somehow?
}
Another thing, how can I reference a product in an order entry, and at the same time set some additional information about it, such as the quantity of a referenced product?
a
Hi @Ludde Bror 👋 To answer your first question about relationships, you need to include both sides of the relationship within your Prisma schema. However if you inspect your database you'll notice that these relation fields define the connection at the Prisma level and do not exist in the database. If you'd like to configure foreign keys in your database you can do so. Regarding your second question, I think you're likely looking for updating specific records via nested writes. Take a look here for more information. Basically you'd write something like this:
Copy code
const update = await prisma.order.update({
    where: {
        id: 1, // Order ID
    },
    data: {
        products: {
            update: {
                where: {
                    id: 2 // Product ID
                },
                data: {
                    your_updated_field: 'Updated value'
                }
            }
        }
    }
})