I am getting an error for the following prisma upd...
# prisma-client
a
I am getting an error for the following prisma updateMany query, not sure if I am formatting it right. I want to update multiple rows by there ID.
Copy code
const updatedPostCount = await prisma.formInput.updateMany({
    where: {
      id: [
        "49523f75-9ec5-471f-999a-62b8097cabcc",
        "51272b87-9592-4121-83f8-a1471abcc540",
      ],
    },
    data: { name: "test mass" },
  });
I get the following error
Copy code
Argument id: Got invalid value 
[
  '49523f75-9ec5-471f-999a-62b8097cabcc',
  '51272b87-9592-4121-83f8-a1471abcc540'
]
on prisma.updateManyFormInput. Provided List<UUID>, expected StringFilter or String.
type StringFilter {
  equals?: String
  in?: List<String>
  notIn?: List<String>
  lt?: String
  lte?: String
  gt?: String
  gte?: String
  contains?: String
  startsWith?: String
  endsWith?: String
  not?: String | NestedStringFilter
}
any help would be great
b
@Anders try this:
Copy code
const updatedPostCount = await prisma.formInput.updateMany({
    where: {
      id: {
        in: [
          "49523f75-9ec5-471f-999a-62b8097cabcc",
          "51272b87-9592-4121-83f8-a1471abcc540",
        ],
      },
    },
    data: { name: "test mass" },
  });
a
oh that's perfect thanks. Do you know if there is a way to pass different data values for each ID, or do they have to be the same?
b
@Anders could you give an example of what you mean by "different data values" please? Just to make sure I understand what you mean 🙂
a
so that the row with the first id would get the value "test #1" and the row with the second ID would get the value "test #2" for the name keys
if that makes sense
b
@Anders ah, so you mean something like
WHERE (id = 'ID 1' AND name = 'Name 1') OR (id = 'ID 2' AND name = 'Name 2')
?
a
yeah precisely, I am going to be recieving an an array containg objects with all these pairs, to update a bunch of fields at once by there id
b
@Anders you can use this style of
where
clause for this:
Copy code
where: {
  OR: [
    {
      id: 'ID 1',
      name: 'Name 1'
    },
    {
      id: 'ID 2',
      name: 'Name 2'
    },
  ]
}
a
ok awesome I will give it a go. Thanks! a bunch
b
No worries! 🙂
a
@Ben Ezard what do I put in that data attribute, says it is required?
b
@Anders that's where you put the actual data that you want to update e.g. if you want to update the
name
field to be
Test Name
then you'd use
Copy code
data: {
  name: 'Test Name'
}
a
ah that's kind of my issue, i want each rows data to be different, if I pass that it will update them all to have that name
b
@Anders Ahh I think you need to do that in multiple queries I'm afraid Either that or write a raw query that uses something like
case
statements in MySQL, or
update from
in Postgres, etc
a
is there a way to just overwrite an entire table with brand new rows like a delete all and a create many. I guess I could loop over my array and send out a query to update for each one. I guess I'll do that.
ok kewl that works. Thanks again.
👍 1