Duplicate relations when using `with`

I'm running into a problem where some duplicate values are being returned through a relation with with.

Basically, I'm getting

[
   {
      "id":"317078bd-6265-4156-986c-085bdf297765",
      "modifierGroups":[
         {
            "menuItemId":"317078bd-6265-4156-986c-085bdf297765",
            "modifierGroupId":"0fd458f3-128a-4787-8253-4d288efcf7c4",
            "order":0,
            "modifierGroup":{
               "id":"0fd458f3-128a-4787-8253-4d288efcf7c4",
               "modifiers":[
                  {
                     "modifierGroupId":"0fd458f3-128a-4787-8253-4d288efcf7c4",
                     "modifierId":"6e43c680-7c41-4840-9ff8-2597d98257ed",
                     "order":0,
                     "modifier":{
                        "id":"6e43c680-7c41-4840-9ff8-2597d98257ed",
                        "ingredient":{
                           "id":"8bb2caab-b758-4cb7-9012-f9e543cf4eb4"
                        },
                        "item":null
                     }
                  }
               ]
            }
         },
         {
            "menuItemId":"317078bd-6265-4156-986c-085bdf297765",
            "modifierGroupId":"0fd458f3-128a-4787-8253-4d288efcf7c4",
            "order":0,
            "modifierGroup":{
               "id":"0fd458f3-128a-4787-8253-4d288efcf7c4",
               "modifiers":[
                  {
                     "modifierGroupId":"0fd458f3-128a-4787-8253-4d288efcf7c4",
                     "modifierId":"6e43c680-7c41-4840-9ff8-2597d98257ed",
                     "order":0,
                     "modifier":{
                        "id":"6e43c680-7c41-4840-9ff8-2597d98257ed",
                        "ingredient":{
                           "id":"8bb2caab-b758-4cb7-9012-f9e543cf4eb4"
                        },
                        "item":null
                     }
                  }
               ]
            }
         }
      ]
   }
]


instead of

[
   {
      "id":"317078bd-6265-4156-986c-085bdf297765",
      "modifierGroups":[
         {
            "menuItemId":"317078bd-6265-4156-986c-085bdf297765",
            "modifierGroupId":"0fd458f3-128a-4787-8253-4d288efcf7c4",
            "order":0,
            "modifierGroup":{
               "id":"0fd458f3-128a-4787-8253-4d288efcf7c4",
               "modifiers":[
                  {
                     "modifierGroupId":"0fd458f3-128a-4787-8253-4d288efcf7c4",
                     "modifierId":"6e43c680-7c41-4840-9ff8-2597d98257ed",
                     "order":0,
                     "modifier":{
                        "id":"6e43c680-7c41-4840-9ff8-2597d98257ed",
                        "ingredient":{
                           "id":"8bb2caab-b758-4cb7-9012-f9e543cf4eb4"
                        },
                        "item":null
                     }
                  }
               ]
            }
         }
      ]
   }
]


You can see that all of the ids are duplicates. I know I ran into this plenty when I was doing my own joined queries, but am I doing something wrong here?

My query is
context.query.menuItems
    .findMany({
      with: {
        modifierGroups: {
          with: {
            modifierGroup: {
              with: {
                modifiers: {
                  with: {
                    modifier: {
                      with: {
                        ingredient: true,
                        item: true,
                      },
                    },
                  },
                  orderBy: modifierGroupModifiers.order,
                },
              },
            },
          },
          orderBy: menuItemModifierGroups.order,
        }
      },
    })


Any help is appreciated, I'm hoping to have this functional sometime tomorrow :) Thanks in advance!
Was this page helpful?