I'm trying to create a relation in my database. I'...
# orm-help
j
I'm trying to create a relation in my database. I've got a datamodel that looks like this (simplified);
Copy code
type CheckIn {
  id: ID! @unique
  location: Location!
  user: User!
}

type User {
  id: ID! @unique
  checkIns: [CheckIn!]
}

type Location {
  id: ID! @unique
  checkIns: [CheckIn!]
}
How can I add
@relation
directives to finish the relationship? Each
CheckIn
has a user and a location, and each
User
and
Location
has a list of `CheckIn`s that refer to it.
And, related question, I don't have a manual way of creating new
Location
entries, but I want to pass in location data when I create a new
CheckIn
. What's the right way to do that? This is how I'm creating the
CheckIn
, but I don't know what to pass in for `location`;
Copy code
async createCheckIn(parent, { title, location }, context) {
    const userId = getUserId(context);
    return context.prisma.createCheckIn({
      title,
      location,
      public: true,
      user: { connect: { id: userId } }
    });
  }