P
Prisma•2mo ago
Nick

New to Prisma, can I not rely on the order of the array when creating nested records?

So referencing organiser.events[0] doesn't seem to refer to Event 1?
const organiser = await prisma.organiser.create({
data: {
id: "kp_cb03a5581e674879b5940cbb5f697575",
firstName: "firstName",
lastName: "lastName",
events: {
create: [{
name: "Event 1",
startOn: new Date("2024-12-15T17:00:00Z"),
description: "Description 1",
status: "live",
address: {
create: {
line1: "456 Snow Avenue",
city: "Manchester",
postcode: "M1 1BB",
},
},
},
{//... more events}
],
},
},
include: {
events: true,
},
});



prisma.rSVP.create({
data: {
attendeeId: attendees[0].id,
eventId: organiser.events[0].id,
status: "going",
},
}),
const organiser = await prisma.organiser.create({
data: {
id: "kp_cb03a5581e674879b5940cbb5f697575",
firstName: "firstName",
lastName: "lastName",
events: {
create: [{
name: "Event 1",
startOn: new Date("2024-12-15T17:00:00Z"),
description: "Description 1",
status: "live",
address: {
create: {
line1: "456 Snow Avenue",
city: "Manchester",
postcode: "M1 1BB",
},
},
},
{//... more events}
],
},
},
include: {
events: true,
},
});



prisma.rSVP.create({
data: {
attendeeId: attendees[0].id,
eventId: organiser.events[0].id,
status: "going",
},
}),
2 Replies
Nurul
Nurul•2mo ago
Hello @Nick 👋 Without an explicit orderBy you will not get any guarantees by Prisma in which order the data is returned. This is because database doesn't guarantee the order without orderBy. So this is expected behaviour. https://www.prisma.io/docs/orm/reference/prisma-client-reference#orderby
Prisma Client API | Prisma Documentation
API reference documentation for Prisma Client.
Nick
NickOP•2mo ago
Hi @Nurul , thanks for the reply. Am I right in thinking that an orderBy wouldn't work when creating these nested events? I ended up creating each event manually anyway, just curious 🙂

Did you find this page helpful?