October 21, 2024
Chicago 12, Melborne City, USA
SQL

How Sorting / Ordering Work on Prisma when Single Row is Updated?


I have a Prisma Models like this:

model Table1 {
  id     String    @id @default(cuid())
  name            String
  table2          Table2[]
  type            ReviewType @default(Null)
  subType         SubType   @default(Null)
  isDefault       Boolean
  accountId       String
  dateCreated     DateTime  @default(now())
  dateModified    DateTime  @updatedAt

  @@unique([name, type, subType])
}

model Table2 {
  id    String    @id @default(cuid())
  name                String
  checklistId         String
  checklistItem       Table3[]
  accountId           String
  type                String
  table1              Table1   @relation(fields: [checklistId], references: https://stackoverflow.com/q/79108612)
  dateCreated         DateTime    @default(now())
  dateModified        DateTime    @updatedAt

  @@index(https://stackoverflow.com/q/79108612)
  @@index([name])
  @@index([checklistId])
}

model Table3 {
  id     String    @id @default(cuid())
  name                String
  checklistGroupId    String
  accountId           String
  type                String
  Table2              Table2 @relation(fields: [checklistGroupId], references: https://stackoverflow.com/q/79108612)
  dateCreated         DateTime    @default(now())
  dateModified        DateTime    @updatedAt

  @@index([checklistGroupId])
  @@index(https://stackoverflow.com/q/79108612)
  @@index([name])
}

and I have a seed data that will populate our database. I just want to ask what is the behavior of prisma when I update one record of the Table2, because it will be position at the bottom of my data when update is made, and on my get method request for table is now reordered.

User didnt update the name field of the row record from the seed (order is important on my end)

1
2
3
4
5

User updated the name field of row record number one

2
3
4
5
1 <- updated

then when I retrieve the record number 1 now is already at the bottom.



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video