Title
a

Anders

03/01/2021, 4:47 PM
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.
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
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

Ben Ezard

03/01/2021, 5:02 PM
@Anders try this:
const updatedPostCount = await prisma.formInput.updateMany({
    where: {
      id: {
        in: [
          "49523f75-9ec5-471f-999a-62b8097cabcc",
          "51272b87-9592-4121-83f8-a1471abcc540",
        ],
      },
    },
    data: { name: "test mass" },
  });
a

Anders

03/01/2021, 5:04 PM
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

Ben Ezard

03/01/2021, 5:05 PM
@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

Anders

03/01/2021, 5:06 PM
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

Ben Ezard

03/01/2021, 5:07 PM
@Anders ah, so you mean something like
WHERE (id = 'ID 1' AND name = 'Name 1') OR (id = 'ID 2' AND name = 'Name 2')
?
a

Anders

03/01/2021, 5:09 PM
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

Ben Ezard

03/01/2021, 5:12 PM
@Anders you can use this style of
where
clause for this:
where: {
  OR: [
    {
      id: 'ID 1',
      name: 'Name 1'
    },
    {
      id: 'ID 2',
      name: 'Name 2'
    },
  ]
}
a

Anders

03/01/2021, 5:12 PM
ok awesome I will give it a go. Thanks! a bunch
b

Ben Ezard

03/01/2021, 5:12 PM
No worries! 🙂
a

Anders

03/01/2021, 5:17 PM
@Ben Ezard what do I put in that data attribute, says it is required?
b

Ben Ezard

03/01/2021, 5:19 PM
@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
data: {
  name: 'Test Name'
}
a

Anders

03/01/2021, 5:20 PM
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

Ben Ezard

03/01/2021, 5:24 PM
@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

Anders

03/01/2021, 5:29 PM
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