P
Prisma4mo ago
dev

Include in findone return null if the join table not have its id

I have table "sometable" and "purchase_items" table. in purchase_items, i have sometable_id. im trying to include purchase_items in findOne purchase_items. it works when purchase_items have data with sometable_id, but it return null when example: sometable has id = 9, but purchase_items has no sometable_id = 9. i want to still get the data, with purchase_items: []. is it posible?
No description
1 Reply
RaphaelEtim
RaphaelEtim4mo ago
Hi @dev can you try this query?
const sometableWithPurchaseItems = await prisma.sometable.findUnique({
where: {
id: 9, // Replace with the ID you are querying
},
include: {
purchase_items: true, // This will include the related purchase_items
},
});
const sometableWithPurchaseItems = await prisma.sometable.findUnique({
where: {
id: 9, // Replace with the ID you are querying
},
include: {
purchase_items: true, // This will include the related purchase_items
},
});
Want results from more Discord servers?
Add your server