How can I insert a new row and connect to an exist...
# orm-help
k
How can I insert a new row and connect to an existing relation given a field that is not unique. I would use
connectOrCreate
but I don't want to create and the fields I'm searching on are not unique
r
Could you provide an example if possible?
k
Yes. Say I have the entities
User
,
Product
,
Manufacturer
and the relations are as
User
1:1
Product
Product
M:1
Manufacturer
. Products and Manufacturers already exist so upon creating a new
User
, I want to connect to a specific
Product
which in turn has a
Manufacturer
given a field that is not unique
r
Connecting without unique fields is not possible. You would need to query for the id of the
Product
first using
findMany
as you do not have a unique field and then connect to the
User
.
k
Ok, thanks
👍 1