say how do i update an array field that references...
# orm-help
b
say how do i update an array field that references another type ?
r
Is it a relational field? Something like:
Copy code
posts: [Post!]!
b
more like
Copy code
input PostInput {
...etc
relatedArticles: [ID]
}
because i get an error if i put a direct reference to the "Articles" type
heres my actual code
Copy code
input TripInput {
  name: String
  """
  The Id returned by the google places API
  """
  location: String
  arivalDay: String
  departureDay: String
  activities: [String]
}
the query
Copy code
updateTrip(
    id: "ckaqhvpun2nib0941gwkop53v"
    input: { activities: ["ckaqpvplbjsgs09926zoy480o"] }
  ) {
    id
    activities {
      id
      name
      suggestedItems {
        name
      }
    }
  }
and the resolver
Copy code
const Trip = await context.prisma.updateTrip({
    data: {
      ...input,
      activities: [
        input.activities.map((active) => ({
          connect: { id: active },
        })),
      ],
    },
    where: { id: args.id },
  });
as in i want to add existing activities to the list
I think this is the right solution, it seems to work
Copy code
const Trip = await context.prisma.updateTrip({
    data: {
      ...input,
      activities: { connect: input.activities.map((a) => ({ id: a })) },
    },
    where: { id: args.id },
  });
👍 1
r
Yes Bob the
connect
would work as it connects to your relations specified.