Hey team, I was using `set` to save the changes be...
# orm-help
w
Hey team, I was using
set
to save the changes between two implict many-to-many relationship and it was working great but as soon as I changed it to explicit which will basically save the order between the other two models, it stop worked.
Copy code
model ModifiersOnItem {
  item    MenuItem          @relation(fields: [itemId], references: [id])
  itemId  String
  group   MenuModifierGroup @relation(fields: [groupId], references: [id])
  groupId String
  order   Int

  @@id([itemId, groupId])
}
The
set
doesn’t reflect the same functionality which is ok but now I’m wondering what would be the best approach for this scenario? Where do I have to update the relation between them and the order? Should I delete all records and add new set again? Something like this, would be cool to have:
Copy code
const item = await prisma.menuItem.update({
        where: {
          id: params.id,
        },
        data: {
          ...data,
          modifiers: {
            set: [
              {
                // groupId: '',
                // order: ''
              },
            ],
          },
        },
      })
r
@Wlad Paiva 👋 Could you share the other models as well? In explicit relations, you need to go a level deeper.
w
Sure thing. They are basic stuff.
Copy code
model MenuModifierGroup {
  id           String               @id @default(uuid())
  name         String
  title        String
  ...
  menuItems    ModifiersOnItem[]
  createdAt    DateTime             @default(now())
  updatedAt    DateTime             @updatedAt
}

model MenuItem {
  id             String               @id @default(uuid())
  name           String               @db.VarChar(40)
  ...
  modifiers      ModifiersOnItem[]
}
r
This should work:
Copy code
prisma.menuItem.update({
    where: {
      id: 'params.id',
    },
    data: {
      modifiers: {
        set: {
          itemId_groupId: {
            groupId: '',
            itemId: ''
          }
        }
      }
    }
  })