Hey all :wave: is there a way to conditionally do ...
# orm-help
e
Hey all 👋 is there a way to conditionally do a
connect
? This doesn't seem to work:
Copy code
location: {
          connect: existingLocation
            ? {
                id: existingLocation?.id,
              }
            : {},
          create: location,
        },
✅ 1
I get this error message
This DOES work in another resolver where it expects an array :
Copy code
locations: {
          connect:
            existingLocations?.map(location => ({
              id: location.id,
            })) || [],
          create: locations,
        },
I would have thought they would work in the same way,
connect
seems happy with an empty array but not empty object?
Hmmm passing
undefined
instead of the empty object seemed to do the trick:
Copy code
location: {
          connect: existingLocation
            ? {
                id: existingLocation?.id,
              }
            : undefined,
          create: location,
        },
r
Yes
undefined
will be ideal in this case as well as for multiple values in
connect
.
e
Thanks @Ryan replaced the empty array aswell now
💯 1