I am trying to `upsert` a record in the database w...
# orm-help
d
I am trying to
upsert
a record in the database where the
orderId
must not have a value.
Copy code
.upsert({
	create: {
	    ...
	},
	update: {
		...
	},
	where: {
		id,
		orderId: undefined
	}
})
orderId
is possible
undefined
because its an optional relation. how can I say in the
where
that is must match an
id
and where `orderId`'s value is empty. afaik
undefined
means do nothing, but I need it to do something
if I use
null
i get this:
Type 'null' is not assignable to type 'string | undefined'.ts(2322)
. This is how its defined in my modal
orderId String? @unique @db.VarChar(255)
z
Copy code
let where = {
  id,
}

if (orderId) where.orderId = orderId;


....
.upsert({
	create: {
	    ...
	},
	update: {
		...
	},
	where,
})
d
no, i actually need
orderId
NOT
undefined
Copy code
where: {
  id,
  orderId: null
}
this is what I actually need
but
null
doesnt work
c
Isn’t the id enough to identify the record you want to update?
d
No, not for my use case
c
How did you define the model?
d
Copy code
model GenericOrder {
   ... 
   orderId String? ... 

   order Order? relation... 
}

model Order {
   ... 
   genericOrders GenericOrder[]
}
c
This should work just fine because this should map to
orderId: string | null
in the prisma client type definitions. It seems instead you have “string | undefined” for some reason. Can you confirm what is in the prisma client type definition
d
orderId?: string
That's what I assumed, but it's undefined it seems
Maybe it's not working with an upsert
c
Oh… I see. Yes it seems it doesn’t work with upsert. Because there is a separate type for whereUniqueInput:
GenericOrderWhereUniqueInput
IMO the id should be enough to identify a unique item. (that’s why it is an ID; ID’s are usually unique)
d
Yes ik. But I also went to search based on null value of orderId
So without an id